Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 15. Virtual Functions and other ... > Conversions Between Classes Related ...

Conversions Between Classes Related Through Inheritance

The use of inheritance introduces additional possibilities for using an object of one type where an object of another type is expected. Classes related through public inheritance are not totally incompatible because a derived class object has all the operations and data members that a base class object has. As you are going to see, one can assign an object of one class to an object of another type (possibly using an explicit cast). One can pass an object of one class as an argument where a parameter of another class is expected (again, you might need a cast).

The C++ rules for conversions between classes related through inheritance are not very complex. It seems, however, that they run against common programming intuition. If this will be the case for you, make sure that you adjust your intuition accordingly. I will try to help you to do so.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial