tags:

views:

79

answers:

2

I have a vector which accepts vectors of GlDouble vectors. But when I try to push one it says:

Error 1 error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const std::vector<_Ty> &' c:\Users\Josh\Documents\Visual Studio 2008\Projects\Vectorizer Project\Vectorizer Project\Vectorizer Project.cpp 324

Why isn't it letting me push this? It's saying it wants a contant but I never specified that....

Thanks

the struct:
struct SHAPECONTOUR{

 std::vector<USERFPOINT> UserPoints;
 std::vector<std::vector<GLdouble>> DrawingPoints;
};

std::vector<std::vector<GLdouble>> shape_verts;

SHAPECONTOUR c;
c.DrawingPoints.push_back(shape_verts);
+3  A: 

Edit: After new additions, the problem is not const - the problem is that you're trying to push the wrong type.

std::vector<std::vector<GLdouble> > v;
v.push_back(std::vector<GLdouble>()); // works; pushing contained type
v.push_back(std::vector<std::vector<GLdouble> >()); // <-- error: trying to push type of container.

Think about if you just had a vector of doubles; you push_back a double into the vector, you don't push_back another vector.

Peter
I never use the const keyword anywhere though
Milo
Are you sure you're not using it implicitly? If the vector is a member of a class and you're in a const member function then it's implicitly const. Or if it's an rvalue (a temporary) you may see a similar effect?
Peter
Also, the const keyword is generally considered useful in C++ - if other programmers have to interoperate with your code, they may find it easier if your member functions are const-correct, for example. Might be worth looking into :)
Peter
+2  A: 

This has nothing to do with const. Your types are wrong. DrawingPoints is a std::vector<std::vector<GLdouble>> which means that it contains items of type std::vector<GLdouble>. You're trying to push_back(shape_verts) which is of type std::vector<std::vector<GLdouble>>. I think what you want is just to make shape_verts a std::vector<GLdouble>.

bshields