c ++ upward shape (upcast)

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/bua200720411091/article/details/39718533
Simply put, shape up is the object of a subclass refers to as a parent object to look at let's take a look at the specific:

        set: Student inherits from Person
        is:   
                Student Person
                Student * Person *
                Student & Person &         
        
           internal principle:
                subclass Most of the parent object has a class object's member, in addition to private members of the parent class. 
                For example, one day the world's only Chinese people, and we say that Joe Smith is a student, then we can put as Joe Smith is China people. we can put Joe Smith this subclass object as Chinese people to look at the parent object, which formed the shape up, but you can find, not the other way round, Joe Smith is the Chinese people, but he is a student it? obviously it is not necessarily.
                
                class the Person {};
                class Student: the Person {public};

                the Person Chinese; 
                Student zhangsan;

                Student * STU = & Chinese;
                Student &stud = stu;
                

Guess you like

Origin blog.csdn.net/bua200720411091/article/details/39718533