的std ::向量; 无法转换参数; Visual Studio 2012

VP.*_*VP. 1 c++ vector std visual-studio-2012

我在VS2012 x64快递版上遇到错误.相同的代码在VS2010下正常工作.我在stackoverflow上经历了很多线程,这似乎是VS2012中的一个错误.

代码:

typedef vector< vector<cv::Point2d> > vec_type; 
vec_type table;
table.assign( 100, 0 );
Run Code Online (Sandbox Code Playgroud)

错误:

错误C2664:' void std::vector<_Ty>::assign(unsigned __int64, const std::vector<cv::Point2d> &)':无法将参数2从' int' 转换为' const std::vector<_Ty> &'

任何人都可以指出解决方案或解决这个问题吗?

谢谢

bil*_*llz 6

vec_typeelement是vector<cv::Point2d>类型,您无法分配0给它,变通方法解决方案可以是:

传递vector<Point2d>默认构造函数

table.assign(100, vector<Point2d>());
Run Code Online (Sandbox Code Playgroud)

或者使用std :: vector :: resize来获得同样的效果:

table.resize(100);
Run Code Online (Sandbox Code Playgroud)