Is there a way by which we can prevent compilers from defining copy constructors, operator = overload for C++ classes.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
You can declare these functions as private which prevents people from using them when working with your class and at the same time prevents the compiler from generating them.
Inherit from a type that declares those functions in the private scope, such as boost::noncopyable.
Or...have a reference member variable :P
FWIW if you ever get around to using Qt then you can use the
Q_DISABLE_COPY
macro:Yes. Derive from boost::noncopyable.
(There're also NIH ways to do that, by declaring the private never-defined methods for operator= and copy constructor, but, please love boost).
Declare those functions yourself and make them private. Also you can didn't write definitions of that functions, so everyone who try to use those functions - will get an linker error.
In C++0x, you'll be able to write
Note that the compiler will not generate converting
NonCopyable::operator=(Other const&)
overloads in any case.