1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| linux@ubuntu:~/11_2$ vim test04.cpp linux@ubuntu:~/11_2$ g++ test04.cpp -o test04 linux@ubuntu:~/11_2$ ./test04 构造函数执行! 例子 析构函数执行! linux@ubuntu:~/11_2$ cat test04.cpp #include<iostream> #include<string> using namespace std; class Dog { public: Dog(); ~Dog(); }; int main() { Dog dog; cout<<"例子"<<endl; return 0; } Dog::Dog() { cout<<"构造函数执行!"<<endl; } Dog::~Dog() { cout<<"析构函数执行!"<<endl; }
|