c++ - Efficient Ransac 的模板化内核存在问题

标签 c++ templates cgal typename

我正在尝试在使用模板化内核的函数中使用 CGAL 的高效 Ransac 算法,这里是要重现的最小代码。

#include <CGAL/property_map.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Shape_detection/Efficient_RANSAC.h>
// Type declarations.
typedef CGAL::Exact_predicates_inexact_constructions_kernel  Kernel;


template < typename K > //comment for working version
void funcTest() {

//typedef   CGAL::Exact_predicates_inexact_constructions_kernel  K;       //uncomment for working version
  typedef   std::tuple<typename K::Point_3,typename K::Vector_3, size_t, bool>     Point_and_normals;
  typedef   CGAL::Nth_of_tuple_property_map<0, Point_and_normals>  Point_map;
  typedef   CGAL::Nth_of_tuple_property_map<1, Point_and_normals>  Normal_map;
  typedef   CGAL::Shape_detection::Efficient_RANSAC_traits
                <K, std::vector<Point_and_normals>, Point_map, Normal_map>             TraitsShape;
  typedef  CGAL::Shape_detection::Efficient_RANSAC<TraitsShape> Efficient_ransac;
  typedef  CGAL::Shape_detection::Plane<TraitsShape> PlaneRansac;

  std::vector<Point_and_normals>  points;
  Efficient_ransac ransac;
  ransac.set_input(points);
  ransac.add_shape_factory<PlaneRansac>();
  ransac.detect();
}

int main (int argc, char** argv) {

  funcTest<Kernel>();   //comment for working version
  //funcTest());        //uncomment for working version
  return 0;
}

在此代码中,模板化版本不会构建并出现此错误

tester.cpp:24:39: error: expected primary-expression before ‘>’ token
    24 |   ransac.add_shape_factory<PlaneRansac>();
       |                                       ^
tester.cpp:24:41: error: expected primary-expression before ‘)’ token
    24 |   ransac.add_shape_factory<PlaneRansac>();

但是,显式内核不存在该问题,我猜测它可能来自类型名问题,但我不确定我在这方面可能做错了什么。 有任何意见、建议欢迎留言

最佳答案

问题是编译器不知道标记 < 是否紧随add_shape_factory之后是小于运算符或模板参数列表的开头。

我们可以使用 .template调用成员函数模板时构造来解决这个问题,如下所示:

ransac.template add_shape_factory<PlaneRansac>();
//-----^^^^^^^^------------------------------------->added template keyword here to indicate that it is a member function template

.template用于告诉编译器 < token 是模板参数列表的开头,并且不小于运算符。

关于c++ - Efficient Ransac 的模板化内核存在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72269958/

相关文章:

c++ - 在屏幕上绘图

templates - 更好的 Grails 模板

c++ - 如何检查Qt中的当前光标形状

c++ - 加减乘除模板函数

c++ - 使用模板模板参数的模板参数

c++ - 使用模板模板参数和 enable_if 获得正确的重载选择

c++ - Mac OS X 上的 CGAL 链接错误

c++ - 如何使用 CGAL 和 CORE 精确计算 sin(2*m*Pi/n)?

c++ - CGAL:沿相交折线的闵可夫斯基和

c++ - 将C++ IPv6字符串表示形式转换为boost::multiprecision::uint128_t