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

时间:2013-02-16 01:19:22

标签: c++ vector visual-studio-2012 std

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

代码:

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

错误:

  

错误C2664:&#39; void std::vector<_Ty>::assign(unsigned __int64, const std::vector<cv::Point2d> &)&#39; :无法转换参数2来自&#39; int&#39;到&#39; const std::vector<_Ty> &&#39;

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

由于

1 个答案:

答案 0 :(得分:6)

vec_type元素为vector<cv::Point2d>类型,您无法为其指定0,解决方法可以是:

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

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

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

table.resize(100);