【问题标题】:Deriving from a CGAL class compatible with CGAL::assign从与 CGAL::assign 兼容的 CGAL 类派生
【发布时间】:2013-01-24 19:24:39
【问题描述】:

我想从 CGAL::Parabola_segment_2 类派生。因为我想访问两个 无法通过公共成员函数访问的受保护数据成员。

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Segment_Delaunay_graph_traits_without_intersections_2< Kernel,
    CGAL::Integral_domain_without_division_tag> Gt;
typedef CGAL::Segment_Delaunay_graph_2<Gt> SDG_2;
typedef SDG_2::Vertex_handle Vertex_handle;
typedef SDG_2::Finite_edges_iterator Finite_edges_iterator;
typedef Gt::Line_2 Line_2;
typedef Gt::Ray_2 Ray_2;
typedef Gt::Segment_2 Segment_2;
typedef Gt::Point_2 Point_2;
typedef Gt::Site_2 Site_2;

class Parabola_segment_2 : public CGAL::Parabola_segment_2<Gt> { };

我的代码可以编译并运行,但下面给出的代码中的 if 语句永远不会返回 true。但我确信它必须为某些值返回 true。

.......
CGAL::Object o = sdg.primal(*eit);
Segment_2 s;
Parabola_segment_2 ps;
if(CGAL::assign(s, o)) {
...
}

如果我改变了

class Parabola_segment_2 : public CGAL::Parabola_segment_2<Gt> { };

与

typedef CGAL::Parabola_segment_2<Gt> Parabola_segmet_2;

然后程序完全按照我的意愿执行,但我无法访问我想要的变量。我的问题是我应该如何派生 CGAL 类以使其与 CGAL::assign() 函数兼容?

【问题讨论】:

    标签: c++ object derived-class assign cgal


    【解决方案1】:

    不要使用模板推导,并明确预期的类型。那就是:

    if( CGAL::assign<CGAL::Parabola_segment_2<Gt> >(ps, o)) {
    ...
    }
    

    【讨论】:

      猜你喜欢
      • 2016-02-04
      • 2011-12-06
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      相关资源
      最近更新 更多