error: 'varName' was not declared in this scope [duplicate]

孤街浪徒 提交于 2019-12-13 16:45:14

问题


I want to find the biggerst contour in my image (with opencv and C++). I have been read this thread: Finding Contours in OpenCV? and Draw the biggest element conncted using areaContours (OpenCV ) but I got error: 'varName' was not declared in this scope, which mean compiler think I haven't been declare that variable right? So this snippet of my code:

    threshold(Img, Img, t, 255, CV_THRESH_BINARY_INV);
    vector<vector<Point>> varName;
    findContours(Img, varName, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

I got this error:

   D:\OpencvWorkspace\....|50|error: 'varName' was not declared in this scope|

Line 50 is this code:

    vector<vector<Point>> varName;

My question. Why compiler ask this variable haven't declare at the line I declare that variable. could someone help me?


回答1:


You have used a pre c++11 standard compiler (as proven in your comment). The older standard had a problem letting the parser disambiguate a pair of closing angle brackets >> used in a nested template type specifier, from the operator>>(). Thus you had to write a space between them:

vector<vector<Point> > varName;
                 // ^ Note the space



回答2:


Yups like πάντα ῥεῖ say. the problem because space between ">" and ">". so I change the declaration from this:

   vector<vector<Point>> varName;

to this one:

   vector<vector<Point> > varName;

By adding space between ">" and ">" and the errror is gone.. Thanks πάντα ῥεῖ



来源:https://stackoverflow.com/questions/29329860/error-varname-was-not-declared-in-this-scope

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!