我想初始化数组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