20次试验
1 #include<iostream> 2 using namespace std; 3 class Myclass 4 { 5 int number; 6 public: 7 Myclass(); 8 Myclass(int); 9 ~Myclass(); 10 void Display(); 11 }; 12 Myclass::Myclass(){cout<<"Constructing nurmally.\n";} 13 Myclass::Myclass(int m):number(m){cout<<"Constructing with a number:"<<number<<endl;} 14 void Myclass::Display() 15 { 16 cout<<"Display a number: "<<number<<endl; 17 } 18 Myclass::~Myclass(){cout<<"Destructing.\n";} 19 int main() 20 { 21 Myclass obj1; 22 Myclass obj2(20); 23 obj1.Display(); 24 obj2.Display(); 25 system("pause"); 26 getchar(); 27 } 28 //Constructing nurmally.Display a number:Destructing. 29 //Constructing with a number:Display a number:Destructing.