Which functions never get inherited while inheriting a class ?

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, 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 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( ) ;

}

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>