編寫一個(gè)創(chuàng)建時(shí),就在屏幕上打印Hello,消失時(shí),就打印Goodbye 的C++程序.
#include<iostream>
using?namespace?std;
class?World{
????????public:
????????????????World(){//創(chuàng)建時(shí)
????????????????????????std::cout<<"Hello!\n";
????????????????}
????????????????~World(){//消失時(shí)
????????????????????????std::cout<<"Goodbye!\n";
????????????????}
};
//World?theWorld;
int?main(){
??????? //cout<<"Hello?World\n";
????????World?theWorld;
????????return?0;
}
[root@portal?ctest]#?vi?hello.c
[root@portal?ctest]#?g++?hello.c?-o?hello
[root@portal?ctest]#?./hello
Hello!
Goodbye!
[root@portal?ctest]#
posted on 2007-09-24 15:05
forker 閱讀(2430)
評(píng)論(0) 編輯 收藏 所屬分類:
cc++