【问题标题】:std::vector; cannot convert parameter; Visual Studio 2012标准::向量;无法转换参数;视觉工作室 2012
【发布时间】:2013-02-16 09:43:59
【问题描述】:

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

代码:

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

错误:

错误 C2664:“void std::vector&lt;_Ty&gt;::assign(unsigned __int64, const std::vector&lt;cv::Point2d&gt; &amp;)”:无法将参数 2 从“int”转换为“const std::vector&lt;_Ty&gt; &amp;

请任何人指出解决方案或解决此问题的方法?

谢谢

【问题讨论】:

  • 这不是 VC++ 2012 中的错误,这是符合标准的改进 – 在 C++11 中 std::vector&lt;&gt; 的构造函数签名已更改并且您拥有的代码 不应该工作。
  • 我不得不问:那段代码应该做什么?
  • @pmr :它应该用 100 个空的 vector&lt;cv::Point2d&gt;s 初始化 table

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


【解决方案1】:

vec_type元素是vector&lt;cv::Point2d&gt;类型,不能给它赋值0,变通方案可以是:

传递vector&lt;Point2d&gt;默认构造函数

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

或使用std::vector::resize 获得同样的努力:

table.resize(100);

【讨论】:

    猜你喜欢
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多