0

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!

kebs
  • 6,387
  • 4
  • 41
  • 70
TSL_
  • 2,049
  • 3
  • 34
  • 55

1 Answers1

2

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.

SirGuy
  • 10,660
  • 2
  • 36
  • 66
  • @Hi GuyGreer! I actually voted up your original answer. I confirm using C++11 (Ubuntu 12.04) and fixed this bug already. Thank you! – TSL_ Jul 08 '14 at 15:34