I have declared my two dimensional array like this. But getting an error due to that
vector <vector <int> > plain(vector <int>(4,0)) = {{23,43,45,56},
{67,85,13,59},
{48,23,9,57},
{24,52,90,12}};
rijndael.cpp:12:51: error: expected ‘,’ or ‘;’ before ‘=’ token
rijndael.cpp:57:1: error: expected ‘}’ at end of input
All prior semi colons have been properly assigned.
Can you tell me where I’m going wrong in this declaration ?
I removed the constructor call and my declaration now is
vector <vector <int> > plain/*(vector <int>(4,0))*/ = {{23,43,45,56},
{67,85,13,59},
{48,23,9,57},
{24,52,90,12}};
But the error now is
rijndael.cpp:15:19: error: in C++98 ‘plain’ must be initialized by constructor, not by ‘{...}’
rijndael.cpp:15:19: error: deducing from brace-enclosed initializer list requires #include <initializer_list>
rijndael.cpp:15:19: error: deducing from brace-enclosed initializer list requires #include <initializer_list>
rijndael.cpp:15:19: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
rijndael.cpp:15:19: error: could not convert ‘{{23, 43, 45, 56}, {67, 85, 13, 59}, {48, 23, 9, 57}, {24, 52, 90, 12}}’ to ‘std::vector<std::vector<int> >’
How do I rectify this ?
Any help is very much appreciated.
You can’t have both a constructor call and a list initialization, stick to one, e.g.:
(You can omit the
=for list initialization.)On your edit: Well, the error explains it all, reading it would help. You need C++11 mode for list initialization. If you don’t want that, you’ll have to copy with the ctor to prepare the 2D array and then fill it in after construction.