Robert
Robert

Reputation: 181

Map of 2d Vectors

I am trying to do the following

std::map <int, std::vector<std::vector<double> > > mapof2Dvectors;

std::vector<std::vector<double> > temp;
for(int u=0; u<size1; u++){
     temp.push_back( std::vector<double> ());
     temp[u].push_back(somedoublehere);
 }
 mapof2Dvectors[key].push_back(temp);

It fails when I try to compile with "error: Semantic Issue: No viable conversion from 'std::vector >' to 'const value_type' (aka 'const std::vector >')"

Any help would be most appreciated.

Upvotes: 2

Views: 2459

Answers (1)

stinky472
stinky472

Reputation: 6797

Might I suggest using some typedefs? The error is actually quite simple.

typedef std::vector<double> Vectors1d;
typedef std::vector<VectorOfDoubles> Vectors2d;
typedef std::map<int, Vectors2d> MapOf2dVectors;

Now you're trying to do this:

MapOf2dVectors mapof2Dvectors;
Vector2d temp;
mapOf2dVectors[key].push_back(temp);

Does this help spot the problem? You're basically trying to push_back Vectors2d into a Vectors2d object when Vectors2d::push_back expects a Vectors1d object. It should be this according to your types:

mapOf2dVectors[key] = temp;

Or faster:

mapOf2dVectors[key].swap(temp);

A simple analogy of your error is like this:

vector<int> v1;
vector<int> v2;
v1.push_back(v2); // error, push_back accepts only a single integer here

So I'm not sure what you're after, but it's probably going to be either this:

v1.insert(v1.end(), v2.begin(), v2.end());

Or this:

v1 = v2;

Upvotes: 4

Related Questions