Re: [問題] C++ class type 及 物件生成疑問
看板C_and_CPP作者KanzakiHAria (神崎・H・アリア)時間7年前發表 (2018/04/09 13:42), 7年前編輯推噓3(3推 0噓 1→)留言4則, 4人參與, 7年前最新討論串2/2 (看更多)
最近怎麼這麼多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
推
04/10 00:23,
7年前
, 1F
04/10 00:23, 1F
推
04/10 03:22,
7年前
, 2F
04/10 03:22, 2F
→
04/10 22:47,
7年前
, 3F
04/10 22:47, 3F
推
04/11 19:09,
7年前
, 4F
04/11 19:09, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):