Move ctor dilemma

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 class?

Upvotes: 2

Views: 183

Answers (2)

Martin v. Löwis
Martin v. Löwis

Reputation: 127467

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.

Upvotes: 0

Motti
Motti

Reputation: 114725

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

Upvotes: 5

Related Questions