2010-06-04 57 views
1

我有一个向量接受GlDouble向量的向量。但是当我试图推一个它说:无法推送GlDouble矢量矢量?

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 

为什么不让我推这个?它说就是了含量的不同,但我从来没有指定....

感谢

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); 
+0

你能给我们你想编译的代码吗? – 2010-06-04 02:25:34

回答

3

编辑:后新增加的,这个问题是不是常量 - 问题是,你要推错误的类型。

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. 

想想你是否只有一个双打矢量;你push_back一个double到vector中,你不会push_back另一个vector。

+0

我从来没有使用const关键字 – jmasterx 2010-06-04 02:25:03

+0

你确定没有隐式使用吗?如果vector是一个类的成员,并且你在一个const成员函数中,那么它是隐含的const。或者如果它是一个右值(临时),你可能会看到类似的效果? – Peter 2010-06-04 02:26:58

+0

此外,const关键字在C++中通常被认为是有用的 - 如果其他程序员必须与您的代码进行互操作,例如,如果您的成员函数是常量正确的,他们可能会更容易。可能值得研究:) – Peter 2010-06-04 02:29:49

3

这与const无关。你的类型是错误的。 DrawingPoints是一个std::vector<std::vector<GLdouble>>这意味着它包含类型std::vector<GLdouble>的项目。您正在尝试push_back(shape_verts),其类型为std::vector<std::vector<GLdouble>>。我想你想要的只是让shape_verts a std::vector<GLdouble>