// By const l-value reference
auto func2 = std::bind([](const std::unique_ptr< std::vector<int> >& pw) // fine
{
std::cout << "size of vector2: " << pw->size() << std::endl;
}, std::make_unique<std::vector<int>>(22, 1));
//By non-const l-value reference
auto func3 = std::bind([](std::unique_ptr< std::vector<int> >& pw) // fine
{
std::cout << "size of vector3: " << pw->size() << std::endl;
}, std::make_unique<std::vector<int>>(22, 1));
// By Value
auto func4 = std::bind([](std::unique_ptr< std::vector<int> > pw) // error
{
std::cout << "size of vector4: " << pw->size() << std::endl;
}, std::make_unique<std::vector<int>>(22, 1));
func4(); // without this line, compilation is fine. The VS generates error for the calling of the bind object.
// By r-value reference
auto func5 = std::bind([](std::unique_ptr< std::vector<int> >&& pw) // error
{
std::cout << "size of vector5: " << pw->size() << std::endl;
}, std::make_unique<std::vector<int>>(22, 1));
func5(); // without this line, compilation is fine.
なぜfunc4とfunc5がコンパイルに失敗するのですか?std :: unique_ptrでlambdaのstd :: bindを使用する
コードはVS2015で正常にコンパイルされます。あなたの側にエラーメッセージを表示してください。 –
@Martin Zhai、行func4()またはfunc5()を追加すると、大量のエラーが表示されます。 – q0987
主な問題は 'std :: bind'です。それが起きると、あなたはまた、最初の間違いをした後に(予想通りに)他のエラーを受け取ります。 – Yakk