Breaking News
Loading...
Wednesday, 22 April 2015

Compiler default methods







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
- See more at: http://labstrikes.blogspot.in/2012/08/adsense-middle-blog-post.html#sthash.gQgSkqx8.dpuf

0 comments:

Post a comment

 
Toggle Footer