Re: 2D Array
On Saturday, June 29, 2013 1:12:00 AM UTC-5, Paavo Helde wrote:
axcytz@gmail.com wrote in
news:ae2340d7-4be6-4e9f-a89f-0c5bfa0b2ce2@googlegroups.com:
On Friday, June 28, 2013 5:37:46 PM UTC-5, =D6=F6 Tiib wrote:
On Saturday, 29 June 2013 01:07:38 UTC+3, axc...@gmail.com wrote:
The error is "c++98 array must be initialized by constructor, not
..}".
Is it something to be fixed?
You likely need to add --std=c++0x (or something like that) to your=
compiler command line to enable C++11 features. It seemingly assumes
you want to compile using C++98 features.
It didn't work out. Is there a way to fix it within the code?
In C++98 style one must either use intermediate raw arrays or construct=
the inner vectors by some other way, e.g. element-by-element. Both
approaches exemplified below:
#include <iostream>
#include <vector>
int main()
{
std::vector< std::vector<int> > array;
=09
int init1[] = {2, 3, 5, 1, 5};
std::vector<int> row1( init1, init1+sizeof(init1)/sizeof(init1[0]));
array.push_back(row1);
int init2[] = {0, 1, 1, 4};
std::vector<int> row2( init2, init2+sizeof(init2)/sizeof(init2[0]));
array.push_back(row2);
=09
std::vector<int> row;
row.push_back(8);
row.push_back(2);
row.push_back(8);
row.push_back(1);
array.push_back(row);
}
Thank you so much for the help Paavo Helde. The method of using intermediat=
e rows is not familiar to me. I presume "row1( init1, init1+sizeof(init1)/s=
izeof(init1[0]));" defines the array init1 and its size by "init1+sizeof(in=
it1)/sizeof(init1[0])". Is it correct? And a critical question is about the=
memory usage. Is it more efficient than using matrix with pointers method?=
Thanks-