Re: [問題] C++ class type 及 物件生成疑問

作者: KanzakiHAria (神崎・H・アリア)   2018-04-09 21:41:58
最近怎麼這麼多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
作者: jerryh001   2018-04-10 00:23:00
new 的也要有括號吧
作者: LPH66 (-6.2598534e+18f)   2018-04-10 03:22:00
new 可以不寫括號, 代表 default initialization
作者: x246libra (楓)   2018-04-10 22:47:00
謝謝您的回覆
作者: lc85301 (pomelocandy)   2018-04-11 19:09:00
還抓分號你人體編譯器嗎XD

Links booklink

Contact Us: admin [ a t ] ucptt.com