【问题标题】:Opencv c++: error: 'it' does not name a typeOpencv C++:错误:“它”没有命名类型
【发布时间】:2014-07-20 08:20:43
【问题描述】:

这段代码在 Windows 上运行完美,但我试图在 linux 上运行它,它给出了这个错误:

在函数'void kmline(cv::Mat, std::vector >&)':| 错误:“它”没有命名类型|错误:预期的‘;’在‘它’之前| 错误:“它”未在此范围内声明| ||=== 构建失败:3 错误,0

警告(0 分钟,3 秒)===|

代码:

void kmline( Mat image, std::vector<Point>& points )

{.
.
.
.
    if (points.size() > 1) //we have 2 points
        {

            for (auto it = points.begin(); it != points.end(); ++it)
            {


            }
        }

}

【问题讨论】:

  • 你用的是什么编译器?
  • 我正在使用 GNU GCC 编译器。
  • gcc -v检查你的版本
  • @LukaszDaniluk gcc 版本 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
  • 你是否使用-std=c++11标志编译?

标签: c++ opencv


【解决方案1】:

使用g++ main.cpp -std=c++11 -lopencv_core -lopencv_highgui 编译并使用命名空间 cv 添加;使用命名空间标准;并包含对我有用的内容。

#include <vector>
#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

void kmline( Mat image, std::vector<Point>& points )

{
  if (points.size() > 1) //we have 2 points                                                                                                                                     
    {

      for (auto it = points.begin(); it != points.end(); ++it)
        {


        }

    }
}

int main()
{
  return 0;
}

【讨论】:

    猜你喜欢
    • 2015-12-01
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    • 2016-01-24
    相关资源
    最近更新 更多