构造与析构
1 #include <iostream> 2 3 using namespace std; 4 5 class info { 6 public: 7 info(int a); 8 info(int a, int b); 9 info(int a,int b,int c); 10 11 ~info(); // 无类型无返无参 12 13 private: 14 int age; 15 int *temp; 16 }; 17 18 19 info::info(int a) { 20 cout << a << endl; 21 temp = new int; 22 } 23 24 info::info(int a, int b) { 25 cout << a << b << endl; 26 temp = new int; 27 28 } 29 30 info::info(int a, int b, int c) { 31 cout << a << b << c << endl; 32 temp = new int; 33 } 34 35 36 info::~info() { 37 delete temp; 38 cout << "析构函数,系统调用,释放空间" << endl; 39 } 40 41 42 int main(void) { 43 44 info info1(7); 45 46 cout << "end" << endl; 47 48 // info1.~info(); 49 50 system("pause"); 51 52 53 return 0; 54 }