作者loveflames (咕啾咕啾魔法陣)
看板C_and_CPP
標題Re: [語法] 請教一題有關ctor/dtor的問題
時間Sun Nov 14 23:34:48 2010
※ 引述《Crysis (Crysis)》之銘言:
: #include <iostream>
: int main()
: {
: std::cout<<"hello\n";
: return 0;
: }
: 題目是要求不動到main()的情況下
: 讓輸出變成
: Constructor xxxx //xxxx的字樣我忘記了, 整句是執行ctor的意思
: hello
: Destructor xxxx
: 猜測是要讓cout成為ostream的物件?
: 但實在想不出要怎麼改..所以來請教大家..
: 謝謝!
如果沒規定一定得用ctor/dtor
可以像下面這樣做
#include <iostream>
int main()
{
std::cout<<"hello\n";
return 0;
}
void bye()
{
std::cout<<"Destructor xxxx\n";
}
int init()
{
std::cout<<"Constructor xxxx\n";
atexit(bye);
}
int haha=init();
沒研究過0x的thread變數
不知道能不能這樣玩
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.252.66.243
推 softwind:@@" 就直接這樣給答案歐... 11/15 02:14
→ loveflames:反正題目要的是ctor/dtor,不能拿這個當答案 11/15 02:21
※ 編輯: loveflames 來自: 111.252.74.157 (11/15 05:31)