我試圖將程序轉換爲OOP。該軟件適用於幾陣:在構造函數上初始化數組
int tipoBilletes[9] = { 500,300,200,100,50,20,10,1,2 };
int cantBilletes[9] = {0};
所以對於我的轉換,我在頭文件中聲明如下:
int *tipoBilletes;
int *cantBilletes;
,並在構造函數中,我寫
tipoBilletes = new int[9];
cantBilletes = new int[9];
tipoBilletes[0] = 500;
tipoBilletes[1] = 300;
tipoBilletes[2] = 200;
...
它的工作原理精細。
我的問題是,是否有任何方式來初始化它像在Java中?
int[] tipoBilletes = new int[]{ 500,300 };
而不是必須一一設置每個元素?
直到新版本的C++出來。但是你應該使用`std :: vector`,而不是`new []`。另外,通過將固定大小的數組更改爲動態數組,可以獲得哪些好處? – GManNickG 2011-01-20 23:12:57
我*仍*無法理解如何不可能有一個簡單的本地對象的數組沒有一個默認的構造函數在舊的C++ ...有沒有他們,就像在C++ 03時忘記它,或者是什麼? – Kos 2011-01-20 23:17:27