C ++ \ templace_back不匹配构造函数参数计数

时间:2016-02-25 10:04:17

标签: c++ c++11 stl stdvector move-semantics

我在这里遇到问题,我不明白。 Afaik std :: vectors emplace_back正在内存中新创建的对象上调用placement new构造函数。

所以这次对emplace_back的调用在c ++ 11中调用了ctor:

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 }
}));

所以据我所知,我可以在这里删除TestData ctor的调用,因为参数传递给了TestData的ctor:

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 }
});

但这会产生错误:

../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);

TestData的ctro是

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

我不明白这一点。有人可以解释为什么emplace_back不能用于正确的参数列表吗?

0 个答案:

没有答案