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

std::vector; cannot convert parameter; Visual Studio 2012

本文关键字:Studio Visual 2012 参数 矢量 std 转换      更新时间:2023-10-16

我在使用VS2012 x64 express版本时遇到错误。同样的代码在VS2010下也能正常工作。我已经在stackoverflow浏览了很多线程,它似乎是VS2012中的一个bug。

代码:

typedef vector< vector<cv::Point2d> > vec_type; 
vec_type table;
table.assign( 100, 0 );

错误:

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

请有人能指出这个问题的解决方案或解决方法吗?

感谢

vec_type元素是vector<cv::Point2d>类型,您不能将0分配给它,解决方法可以是:

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

table.assign(100, vector<Point2d>());

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

table.resize(100);