Re: [問題] 動態產生的物件指標陣列,只能存取第0個

看板C_and_CPP (C/C++)作者 (天亮damody)時間12年前 (2014/04/03 15:17), 12年前編輯推噓1(102)
留言3則, 3人參與, 最新討論串2/3 (看更多)
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
我是想要has a Command這個類別的物件耶
04/04 10:39, 2F

04/04 12:55, , 3F
什麼has a Command類別的物件? 你原文沒講
04/04 12:55, 3F
文章代碼(AID): #1JFGhrRn (C_and_CPP)
文章代碼(AID): #1JFGhrRn (C_and_CPP)