Re: [語法] 請教一題有關ctor/dtor的問題

看板C_and_CPP作者 (咕啾咕啾魔法陣)時間15年前 (2010/11/14 23:34), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《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

11/15 00:09, , 1F
http://codepad.org/XmBex1nY 我想到的是這樣
11/15 00:09, 1F

11/15 02:14, , 2F
@@" 就直接這樣給答案歐...
11/15 02:14, 2F

11/15 02:21, , 3F
反正題目要的是ctor/dtor,不能拿這個當答案
11/15 02:21, 3F
※ 編輯: loveflames 來自: 111.252.74.157 (11/15 05:31)
文章代碼(AID): #1Cu06ReW (C_and_CPP)
文章代碼(AID): #1Cu06ReW (C_and_CPP)