模板编译错误在Ubuntu和使 [英] template compilation error in Ubuntu and make
问题描述
我在Windows中使用MSVS 2008编写和编译了C ++函数。他们有一些模板。
I've got C++ functions written and compiled with MSVS 2008 in Windows. They have some templates.
这些函数在Windows中编译和工作正常,但是当我在Ubuntu中使用make编译同一个项目时,会产生错误。这是模板
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);
}
}
错误不断重复:
‘points’ was not declared in this scope
有没有任何选项与make或CMake为模板创建这样的错误?
Is there any option with make or CMake that creates such error for template?
非常感谢!
推荐答案
标记你的问题C ++ 11,我只能假设你没有为你的编译器启用它。这意味着
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
解释为:
cv::Mat_<cv::Vec<NumType, (2>> points)
b $ b
2>> points
被解释为位移位运算符,这就是为什么它正在寻找一个名为 points
的变量。
The 2>> points
gets interpreted as the bit shift operator and that's why it's looking for a variable named points
.
关于C ++ 11的注释是因为在这个版本中,如果可能的话,>>
会被解释为模板参数列表的两端,意思是你的语法是正确的。
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.
解决方案是在你的编译器中启用C ++ 11或关闭两个模板参数列表,如下所示:
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
注意添加的新空间。
这篇关于模板编译错误在Ubuntu和使的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!