Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 不能推GlDouble的向量吗?_C++_Vector - Fatal编程技术网

C++ 不能推GlDouble的向量吗?

C++ 不能推GlDouble的向量吗?,c++,vector,C++,Vector,我有一个向量,它接受双向量的向量。但当我试着推一个时,它说: 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

我有一个向量,它接受双向量的向量。但当我试着推一个时,它说:

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

编辑:添加新内容后,问题不是常量-问题是您试图推送错误的类型

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.

想想看,如果你有一个双向量;您将一个双精度输入到向量中,而不会将另一个向量返回。

编辑:新添加后,问题不是常量-问题是您试图输入错误的类型

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.

想想看,如果你有一个双向量;你把一个双精度推回向量,你不会把另一个向量推回。

这与常数无关。你的类型不对。DrawingPoints是std::vector,这意味着它包含std::vector类型的项。您正在尝试推送std::vector类型的反形状顶点。我想你想要的只是把形状变为std::向量。

这与常数无关。你的类型不对。DrawingPoints是std::vector,这意味着它包含std::vector类型的项。您正在尝试推送std::vector类型的反形状顶点。我想你想要的只是让shape\u verts成为一个std::vector。

我从不在任何地方使用const关键字,尽管你确定你没有隐式使用它吗?如果向量是一个类的成员,并且你在一个常量成员函数中,那么它隐式地是常量。或者,如果它是一个临时值,你可能会看到类似的效果。而且,const关键字通常被认为是C++中有用的。如果其他程序员必须与你的代码进行交互,那么如果你的成员函数是const正确的,那么它们可能会更容易找到。可能值得一看:我从不在任何地方使用const关键字,尽管你确定你没有隐式地使用它吗?如果向量是一个类的成员,并且你在一个常量成员函数中,那么它隐式地是常量。或者,如果它是一个临时值,你可能会看到类似的效果。而且,const关键字通常被认为是C++中有用的。如果其他程序员必须与你的代码进行交互,那么如果你的成员函数是const正确的,那么它们可能会更容易找到。可能值得研究:你能给我们你试图编译的代码吗?你能给我们你试图编译的代码吗?