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

}

It's very calm over here, why not leave a comment?

Leave a Reply




Categories

UserOnline

Improve the web with Nofollow Reciprocity.

Powered by Yahoo! Answers