Can base class reference is initialized with derived class object ?

We can declare a reference  to base class and initialize it with derived class’s object as shown in the following program..

#include <iostream.h>

class B

{

public:

int i ;

B( )

{

}

} ;

class D : public B

{

public:

D( )

{

}

} ;

main( )

{

D d ;

B &b = d ;

}

Subscribe / Share

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

Leave a Reply




Categories

Powered by Yahoo! Answers