Observe the address space and content of the two objects generated in the following procedures
/ ** /
/ ************************************************** ******************************************************************************************************************************************************** Special *********************************************************** ** /
#include
#include
// base class
Class
CMYBASE ...
{INT X; PUBLIC: INT setX (int nvalue) ... {return x = nvalue;} int getX () ... {Return X;} void print () ... {cout << "in the base class : X = "<< x << endl;}}
;//Derived class
Class CMYDERIVE: PUBLIC
CMYBASE ...
{INT X; // Member variable in the derived class hides the member variable of the base class PUBLIC: int setx (int nvalue) ... {returnix x = nvalue;} int getX () ... {Return x;} // Member function in the base class is redefined void print () ... {cout << "in the derive class: x =" << x << endl;}}
Main () ...
{CMYBASE OBJ1; Obj1.setx (1000); Obj1.Print (); cout << "in main function, in the base class: x = << obj1.getx () << endl; cout << endl; cmyderive Obj2; obj2.setx (300); obj2.print (); obj2.cmybase :: print (); cout << "in main function, in the derived class: x =" << obj2.getx () << ENDL COUT << "in main function, in the base class: x =" << obj2.cmybase :: getX () << endl; obj2.cmybase :: setX (200); obj2.print (); obj2.cmybase :: Print (); cout << "in main function, in the derived class: x =" << obj2.getx () << endl; cout << "in main function, in the base class: x =" < 1. The value of the object class and the object of derived class. The base class and the address of the members of the derived class 3. The address of the base class and the object of the target and the address of its member variable