Avoid using generated copy constructor and operator= by default.
- If you want your object to be copiable.
- If every attribute can be trivially copied, comment clearly you are using implicit copy constructor and operator= deliberately.
- Otherwise, write your own constructors, using the initialization field to initialize attributes and following the header order (which is the real construction order).
- If still don't know (default option) or you think you dont want to copy the objects of a certain class, declare its copy constructor and operator= as private. This way the compiler will let you know when you are doing something you don't want to do.
class foo
{
//...
private:
foo( const foo& );
const foo& operator=( const foo& );
};
Or in a cleaner way if you are using boost:
class foo : private boost::noncopyable
{
...
};