简体   繁体   中英

VS2010 bind implementation doesn't support move-only types?

I've found that the following code doesn't compile in Visual Studio 2010 (but works fine in GCC):

using namespace std;
unique_ptr<string> up(new string("abc"));
auto bound = bind(&string::size, move(up));
bound();

The error I get is:

'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'

Is it because the VS2010 bind implementation just doesn't support move only types?

Your guess is correct: The Visual C++ 2010 implementation of std::bind is not move-aware. See the bug report, "std::bind and std::function are not move-aware."

This is fixed in the forthcoming version, Visual C++ 11. The fix should be present in the Visual C++ Developer Preview that was released in September.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM