Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

c++ - Default Move Constructor in Visual Studio 2013 (Update 3)

I've been able to find multiple conversations about this in the past (e.g. here), but such conversations are from quite a while ago. The code I have a question about is:

#include <utility>
#include <iostream>

struct Foo
{
    Foo() = default;
    Foo(const Foo &o)
    {
        std::cout << "copy" << std::endl;
    }
    Foo(Foo &&o)
    {
        std::cout << "move" << std::endl;
    }
};

struct Bar
{
    Foo foo;
};

int main(void)
{
    Bar a;
    Bar b(a);
    Bar c(std::move(a));
}

If you execute the code in Visual Studio 2013 (Update 3), it prints out "copy" for both cases. If the standard hasn't changed since the answer in the link above, then the output should be "copy" followed by "move." Ideone seems to give the correct output. Is this just something that Visual Studio hasn't implemented yet, or is there something missing in my code? I know that you cannot mark move constructors as default, but that does not imply that the compiler does not support generating default move constructors all-together.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I know that you cannot mark move constructors as default, but that does not imply that the compiler does not support generating default move constructors all-together

Unfortunately, that's exactly what that means. VS2013 does not support implicit generation of move constructors and move assignment operators. If it did, they wouldn't really have a reason to disallow the = default syntax, especially since you're allowed to do that for the copy constructor and assignment operator.

Quoting MSDN: Support For C++11 Features (Modern C++)

"Rvalue references v3.0" adds new rules to automatically generate move constructors and move assignment operators under certain conditions. However, this is not implemented in Visual C++ in Visual Studio 2013, due to time and resource constraints.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...