【发布时间】:2011-09-20 17:34:34
【问题描述】:
我看不出以下(非常做作的)代码有什么问题。这可能是我在mystruct 中声明大小为 2 的向量的方式。但这不就是我们声明一个大小为 2 的向量的方式,它的内容我们还没有初始化吗?
struct mystruct
{
int a;
int b;
vector<double> c(2); };
int main(int argc, char *argv[])
{
mystruct test;
(test.c)[0]=3.4;
(test.c)[1]=1.8;
return 0; }
编译器向我抛出以下错误消息:
g++ -Wall simple.cpp
simple.cpp:18:错误:数字常量之前的预期标识符
simple.cpp:18: 错误:数字常量前应为“,”或“...”
simple.cpp:在函数'int main(int, char**)'中:
simple.cpp:32:错误:数组的无效类型“[int]” 下标
simple.cpp:33:错误:数组下标的无效类型“[int]”
【问题讨论】: