Rule Of The Big Three

In the context of C++ (WikiName: CeePlusPlus) the RuleOfTheBigThree states the following:

Any class requiring a destructor, copy constructor, or an assignment operator must have all three implemented. But there are exceptions--see below.

All this gets at is if any of these are written, it can be assumed that there are "extra" resources somewhere in the class that must be dealt with.

I can think of a class that has a copy constructor and assignment operator but no destructor. The simplest example that comes to mind is if every object of that class has a serial number, in which case the copy constructor must give the newly created copy a new serial number, the assignment operator must avoid copying the source's serial number to the destination, and no destructor is necessary unless one would be necessary for another reason. On the other hand, I can't think of a class that needs a destructor and does not also need an assignment operator and a copy constructor. -- AndrewKoenig

But what happens to a serial number if no longer needed? Both copying and assignment require some sort of registry to keep track of serial numbers... it's an external resource. -- WilliamUnderwood

In the model I have in mind, each object's serial number is stored as part of the object itself. No serial number is ever reused (so the serial numbers must be capable of storing the total number of objects that the program creates during its execution). When an object is copied, the copy is a new object, so it gets a new serial number. When one object is assigned to another, both objects retain their identity - it is just the contents that change - so the objects' serial numbers don't change. -- AndrewKoenig

I thought I recalled one associated with smart pointers, pimpls, and incomplete types. When I drop a std::auto_ptr<IncompleteT> into a class C, doesn't 5.3.5/5 require that I replace the implicitly generated destructor?

Wouldn't an abstract base class with no data members require a virtual destructor, but not an assignment operator or copy constructor? -- ChrisHines


EditText of this page (last edited September 28, 2004) or FindPage with title or text search