Re: [問題] 動態產生的物件指標陣列,只能存取第0個
class RemoteControl
{
private:
int* onCommand;
int* offCommand;
public:
RemoteControl(int No)
{
onCommand = new int[No];
// 除非你的語意是
*((int**)&onCommand+1) = new int();
//才可以,總之自己加大括號轉型吧
}
};
左值是什麼?
http://msdn.microsoft.com/zh-tw/library/wxy5f14h.aspx
簡單來說就是不存在於記憶體的臨時變數。
你至少要找個變數存起來,像這樣:
int* a = onCommand+1;
a = new int();
最後,感謝 uranusjr 的上色器。
發現這個上色器會吃 \t 啊
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.118.175.39
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1396509429.A.6F1.html
※ 編輯: damody (140.118.175.39), 04/03/2014 15:26:36
→
04/04 00:19, , 1F
04/04 00:19, 1F
推
04/04 10:39, , 2F
04/04 10:39, 2F
→
04/04 12:55, , 3F
04/04 12:55, 3F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 3 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
-4
5