开发者

Move ctor dilemma

开发者 https://www.devze.com 2023-01-26 06:02 出处:网络
In order to disable copying of my class I\'m suppose to declare as private but not define operator=(const MyClass&) and MyClass(const MyClass&) - do I have to also disable move ctor for this c

In order to disable copying of my class I'm suppose to declare as private but not define operator=(const MyClass&) and MyClass(const MyClass&) - do I have to also disable move ctor for this cla开发者_如何学Css?


It is still up to discussion whether move constructors will be implicitly generated (and when).

See this PDF by Stroustrup from 2010-10-17 with the subtitle Should move operations be generated by default?

BTW, in C++0x you can = delete functions rather than make them priviate and undefined.

class non_copyable {
    public:
    non_copyable(const non_copyable&) = delete;
    non_copyable& operator=(const non_copyable&) = delete;
};


Quoting from the VS 2010 documentation:

Unlike the default copy constructor, the compiler does not provide a default move constructor.

So for VS 2010, it's not necessary to hide that. They don't specifically discuss default move assignment operators, but I assume they won't generate one, either.

0

精彩评论

暂无评论...
验证码 换一张
取 消