最近怎麼這麼多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