Re: How to define a this particular type?
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:fj6lhd$c9r$1@news.datemas.de...
suresh wrote:
How to define a two dimensional array where each row is of type
vector<map<string,int>>?
There is no way. You cannot define a two-dimensional array where
rows (one-dimensional arrays, the first-level elements) are objects
of some other type. It's just plain nonsense.
You can however, define a _one-dimensional_ array of those vectors:
vector<map<string,int> > myOneDimArray[12345];
My idea is, if "x" is such a variable, x[0] is a vector where each
cell of the vector is a map<string,int>.
Similarly x[1] is a vector where each cell of it is a map<string,int>.
Right. It's not a two-dimensional array, though.
Why do you say there is no way? Although it's very easy to confuse oneself
accessing an element, what is wrong with this code?
#include <iostream>
#include <vector>
#include <string>
#include <map>
typedef std::map<std::string, int> KeyMapType;
int main()
{
std::vector<std::vector<KeyMapType > > x;
x.push_back( std::vector<KeyMapType >() );
x.push_back( std::vector<KeyMapType >() );
x.push_back( std::vector<KeyMapType >() );
x[0].push_back( KeyMapType() );
x[0].push_back( KeyMapType() );
x[0].push_back( KeyMapType() );
x[0][0]["0 1"] = 11;
x[0][0]["0 2"] = 12;
}