Posted by : Sushanth Monday 14 December 2015

Default methods written by compiler:
If nothing is declared inside a class as shown below
Class Empty
{
};
The compilers will declare their own versions of a copy constructor, an assignment operator, a destructor, and a pair of address-of operators as shown below.

All the above methods are public.
The following code will cause each function to be generated.

The default copy constructor (assignment operator) performs member wise copy construction (assignment) of the non-static data members of the class.

Example:
Consider the definition of the named template



Since the class has one constructor defined, the compiler does not generate the default constructors.

NamedObject<int> no1("Smallest Prime Number", 2);
NamedObject<int> no2(no1);      // calls copy constructor

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Technical Articles - Skyblue - Powered by Blogger - Designed by Johanes Djogan -