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 ;

}

This entry was posted in C Programming, C++, VC++. 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>