C++: What are the functions which do not get inherited?
What are the functions that do not get inherited?
constructor, destructor, assignment operator function and a copy constructor are the functions which do not get inherited.
However if their definitions are not provided in the derived class, the compiler adds them automatically.
For example, in the following program although the assignment operator function and copy constructor are not defined in derived class der the statement
der d1 = d ;
invokes copy constructor provided by the compiler and so the statement
der d1 = d ;
works properly.
#include <iostream.h>
class base
{
private :
int i ;
public :
base( )
{
i = 10 ;
}
base operator = ( base b )
{
i = b.i ;
}
base ( base &b )
{
i = b.i ;
}
} ;
class der : public base
{
private :
int ii ;
public :
der( )
{
ii = 20 ;
}
void print( )
{
cout << ii ;b
}
} ;
void main( )
{
der d ;
der d1 = d ;
d1.print( ) ;
}




Comments
Log in or create a user account to comment.