/********************************************************************************************* program Function: C + + On the---of the essence of the object of class implementation results: 1--experimental results show that class objects in C + + and class objects in the Java language----not the same thing 2--java class objects in C + + are reference types---are equivalent to a pointer, and the class object is not a pointer type location Time: Shaanxi Normal University 2016.4.21 author information: September ****************************************************************************
/#include <iostream> using namespace std;
The definition class person{Public:person (int id,int age) for the "1" person class;
~person ();
Private:int ID;
int age;
};
Implementation of a member function in the "2" Person class::P erson (int id,int age) {this->id=id;
this->age=age;
cout<< "I am a constructor for the person class" <<endl;
cout<< "Age:" <<this->age<<endl;
cout<< "Name:" <<this->id<<endl;} Person::~person () {cout<< "I am a destructor of the person class and I invoke it at the end of the class object lifecycle!"
<<endl; int main (int argv,char** argc) {//"1" Object pointer variable--xiaoming This is a pointer variable that has only 4 bytes of storage space (32-bit machine) to store the first address of the space opened by the New keyword person*Xiaoming=new person (1990,20);
Cout<<sizeof (xiaoming) << "bytes" <<endl;
"2" Class object variable, tired is equivalent to a data type, and wangming is a type variable, its size by the data members in this class space to determine the size of the person Wangming=person (199,25);
cout<< "Because there are only two shape variables in the class of person, the size of its class object memory space should be 8 bytes" <<sizeof (wangming) << "byte" <<endl;
System ("pause");
return 0;
}
The results of the program's operation are as follows: