作者KanzakiHAria (神崎・H・アリア)
看板C_and_CPP
標題Re: [問題] C++ class type 及 物件生成疑問
時間Mon Apr 9 21:41:58 2018
最近怎麼這麼多C++基本問題 期中考要到了?
C++實作了call by value / call by reference / call by address 所以符號比較多
※ 引述《x246libra (宸火)》之銘言:
: class classA
: {
: public:
: int num;
: }
// you forgot ;
;
// the type of aaa is classA
auto aaa =
classA();
// the type of bbb is classA&
auto &bbb = aaa;
// the type of ccc is classA*
auto ccc = new
classA;
// to use aaa, bbb, ccc
aaa.num = 0;
bbb.num = 1;
(*ccc).num = 2;
// delete to avoid leaking
delete ccc;
因為C++有reference 所以class是value type沒錯 有&才是reference type
剩下的原文推文有說了 new會在heap 剩下的非static變數會在stack
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.166.81.57
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1523281321.A.92D.html
※ 編輯: KanzakiHAria (118.166.81.57), 04/09/2018 22:13:28
推 jerryh001: new 的也要有括號吧 04/10 00:23
推 LPH66: new 可以不寫括號, 代表 default initialization 04/10 03:22
→ x246libra: 謝謝您的回覆 04/10 22:47
推 lc85301: 還抓分號你人體編譯器嗎XD 04/11 19:09