I am unable to see what is wrong in the following (very contrived) code. It might be the way I have declared a size 2 vector inside the mystruct. But isn’t that how we declare a vector of size 2 whose contents we have yet to initialize?
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; }
The compiler is throwing me the following error message:
g++ -Wall simple.cpp
simple.cpp:18: error: expected identifier before numeric constant
simple.cpp:18: error: expected ‘,’ or ‘…’ before numeric constant
simple.cpp: In function ‘int main(int, char**)’:
simple.cpp:32: error: invalid types ‘[int]’ for array
subscript
simple.cpp:33: error: invalid types ‘[int]’ for array subscript
You cannot initialize
mystruct::cin the class definition, this has to be done in the constructor.