【问题标题】:Type defined in template class "does not name a type"模板类中定义的类型“未命名类型”
【发布时间】:2013-01-23 02:14:13
【问题描述】:

几周前我开始使用模板,但我在使用它时遇到了问题。 我收到了这个错误:

Freestyle/_gl/../_convection_selective/Definitions.h:153:9: error: 'Node_handle' in 'Point_set {aka struct Kd_tree_patch > >*, My_point_property_map, CGAL::Search_traits >>, const double*, Construct_coord_iterator> > >}' 没有命名类型

编译这段代码时:

“定义.h”:

#include "Kd_tree_patch.h"
[...]
template <class SearchTraits, class Splitter_= CGAL::Sliding_midpoint<SearchTraits>, class UseExtendedNode = CGAL::Tag_true > class Kd_tree_patch;  //forward declaration

typedef Kd_tree_patch<Search_traits> Point_set;    
typedef Point_set::Node_handle Node_handle;

“Kd_tree_patch.h”

template <class SearchTraits, class Splitter_=Sliding_midpoint<SearchTraits>, class UseExtendedNode = Tag_true >
class Kd_tree_patch {
[...]
typedef Kd_tree_node<SearchTraits, Splitter, UseExtendedNode > Node;
typedef typename Compact_container<Node>::iterator Node_handle;
};

为什么 Node_handle 还不被视为一种类型?

感谢您的帮助。

【问题讨论】:

  • 你缺少typename 那里(它是一个依赖类型)...
  • 您是几周前开始使用模板的吗?天哪。
  • @NIm 你的意思是:typedef typename Point_set::Node_handle Node_handle;如果是这样,我试过了,但我得到了同样的错误。

标签: c++ templates


【解决方案1】:

您不能前向声明嵌套类型,这意味着要能够使用嵌套类型Node_handle,模板Kd_tree_patch 必须在typedef 之前定义。一旦你解决了这个问题,你还需要通过使用typename 来指示编译器它是一种类型:

typedef typename Point_set::Node_handle Node_handle;
//      ^^^^^^^^

【讨论】:

    猜你喜欢
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 2010-09-20
    • 1970-01-01
    • 1970-01-01
    • 2015-10-06
    • 2023-01-03
    相关资源
    最近更新 更多