Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALL copyable classes should implement BOTH copy constructor and assignment operator, or none #227

Open
jakepetroules opened this issue Apr 7, 2013 · 0 comments
Labels
Milestone

Comments

@jakepetroules
Copy link
Contributor

Any class that is intended to be copyable should override BOTH the copy constructor and the assignment operator, never only one of them. I have experienced real issues with the MSVC compiler when failing to do so.

MyClass(const MyClass &);
MyClass &operator=(const MyClass &);

If the class is not designed to be copied, it MUST disable the operators like so:

class MyClass
{
    Q_DISABLE_COPY(MyClass)
    ....

TLDR; you override both the copy constructor and assignment operator, or disable both.

Some useful info: https://qt-project.org/doc/qt-4.8/qobject.html#Q_DISABLE_COPY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant