template compilation error in Ubuntu and make

倾然丶 夕夏残阳落幕 提交于 2019-12-12 00:58:36

问题


I've got C++ functions written and compiled with MSVS 2008 in Windows. They have some templates.

The functions are compiled and work just fine in Windows, but when I compile the same project in Ubuntu with "make", it generates errors. Here's the template

template <class NumType>
void drawCircles(cv::Mat& image, const cv::Mat_<cv::Vec<NumType, 2>> points, cv::Scalar color)
{
    // added working for both row/col point vector

    Point2d p0;

    for (int i = 0; i < points.cols; i++)
    {
        p0.x = cvRound(points.at<Vec<NumType, 2>>(0,i)[0]);
        p0.y = cvRound(points.at<Vec<NumType, 2>>(0,i)[1]);
        circle(image, p0, 5, color, 2, 8);
    }
}

the error keeps repeating that:

‘points’ was not declared in this scope

Is there any option with make or CMake that creates such error for template?

Thank you at best!


回答1:


Since you haven't tagged your question C++11, I can only assume that you haven't enabled it for your compiler. This means that

    cv::Mat_<cv::Vec<NumType, 2>> points

is interpreted as:

    cv::Mat_<cv::Vec<NumType, (2>> points)

The 2>> points gets interpreted as the bit shift operator and that's why it's looking for a variable named points.

The comment about C++11 is because this situation changed in this version where >> will be interpreted as two end of template parameter lists if possible, meaning your syntax would be correct.

The solution is to either enable C++11 in your compiler or close two template parameter lists like this:

    cv::Mat_<cv::Vec<NumType, 2> > points

Note the new space added.



来源:https://stackoverflow.com/questions/24608032/template-compilation-error-in-ubuntu-and-make

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