我想初始化數組car.places [2] [3] ,但數組中始終爲零。 請誰能告訴我什麼I'm做錯了, 這裏是代碼:C++錯誤初始化數組
#include <iostream>
#include <string>
using namespace std;
class reserv
{
public:
int places[2][3];
} car;
int main() {
car.places[2][3] = (
(1, 2, 3),
(4, 5, 6)
);
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
cout << i << "," << j << " " << car.places[i][j] << endl;
}
}
return 0;
}
我得到這樣的警告形成編譯:
>g++ -Wall -pedantic F_car_test.cpp
F_car_test.cpp: In function 'int main()':
F_car_test.cpp:16:11: warning: left operand of comma operator has no effect [
-Wunused-value]
(1, 2, 3),
^
F_car_test.cpp:16:14: warning: right operand of comma operator has no effect
[-Wunused-value]
(1, 2, 3),
^
F_car_test.cpp:17:11: warning: left operand of comma operator has no effect [
-Wunused-value]
(4, 5, 6)
^
F_car_test.cpp:17:14: warning: right operand of comma operator has no effect
[-Wunused-value]
(4, 5, 6)
^
由於提前,
「Theres在數組中始終爲零」您是什麼意思?你只得到零? –
沒關係!我讀錯了.. –
你沒有初始化數組,你正在分配給它。你不能分配給數組。 – Barmar