Wednesday, June 6, 2007

C++ item 5

An empty class isnt really empty.

A compilergenerates definition for these functions automatically.

Default constructor if u don't have a constructor

Copy constructor
Copy assignemtn

Class Empty {
        Empty() {}
Empty( const Empty& rhs) { }
~Empty() { }
Empty& operator=(const Empty& rhs) { }


These are generated only if needed, but are esily needed for .e.g
Empty e1
Empty e2(e1)
E2 = e1

Causes generation of all of them

What does it mean : compilers reject implicit copy assignment operators in derived classess that inherit from base classes declaring the copy assignment operator private. ?

Things to remember:

Compilers may implicitly generate a class's default constructor , copy constructor , copy assignment operator and destructor

Umesh Kumar

No comments: