jeudi 25 février 2016

C++ emplace_back mismatching constructor parameter count

I'm having a problem here i don't understand. Afaik std::vectors emplace_back is calling the placement new constructor on the newly created object in memory.

So this call for emplace_back calls the move ctor in c++11:

std::vector<TestData> testData;
testData.emplace_back(TestData(Algorithm::GrayscaleTransformation, Image(64, 64, 1), Image(64, 64, 1), { // Mirror, f(x) := 1 - x
    { ParamID::GrayscaleTransformationScale, -1.0f },
    { ParamID::GrayscaleTransformationOffset, 1.0f }
}));

So in my knowledge i can remove the call of the TestData ctor here as the parameters are passed to the ctor of TestData:

std::vector<TestData> testData;
testData.emplace_back(Algorithm::GrayscaleTransformation, Image(64, 64, 1), Image(64, 64, 1), { // Mirror, f(x) := 1 - x
    { ParamID::GrayscaleTransformationScale, -1.0f },
    { ParamID::GrayscaleTransformationOffset, 1.0f }
});

But this yields an error:

../gpuperf_v2/main.cpp:9:10: error: no matching member function for call to 'emplace_back'
testData.emplace_back(Algorithm::GrayscaleTransformation, Image(64, 64, 1), Image(64, 64, 1), { // Mirror, f(x) := 1 - x
~~~~~~~~~^~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_vector.h:924:9: note:     candidate function not viable: requires 3 arguments, but 4 were provided
    emplace_back(_Args&&... __args);

The ctro for TestData is

TestData(Algorithm algorithm, Image const & data, Image const & reference, TestParameters const & params);

I don't understand this. Can somebody explain why emplace_back won't work with the correct parameter list?

Aucun commentaire:

Enregistrer un commentaire