看板 EE_DSnP 關於我們 聯絡資訊
我在寫project遇到了以下的問題, 雖然用一些我覺得很不好的方式解決了, 但還是蠻curious 問題一. class裡的矩陣不知怎麼初始化。 例如 class A 裡有個anotherClass* arr [int], 在constructor A()裡我不知如何初始化上述矩陣, 我試過 A():anotherClass* arr [int](0),...other data member{} 但沒用 所以我最後是乾脆不初始化array 即 A():other data member{} 這樣array裡的值應該也會自動初始為零巴? 問題二. 承接上個問題,在anotherClass* arr [int]裡 那個int必須在程式執行中決定 可是這樣我就無法在class A裡寫 private: anotherClass* arr [int]; 我想過用static data member 但compiler仍是說 "data member may not have variably modified type" 後來我查了一下, 發現有vector這種動態矩陣可以在執行過程中決定array大小 但當我改成 private: vector<anotherClass*> arr; compiler卻說 "ISO C++ forbids declaration of `vector' with no type" 似乎自定義的型態vector不接受 恩,因此我最後只好把那個int直接assign一個安全的值給他 但這樣真的感覺很弱 希望各位強者給點建議 -- 發現array其實是個麻煩的東西 string是好物阿... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.240.243 ※ 編輯: BloodyDuke 來自: 140.112.240.243 (01/16 01:43)