在模板类中定义的类型“不命名类型” [英] Type defined in template class "does not name a type"

查看:244
本文介绍了在模板类中定义的类型“不命名类型”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个星期前我开始使用范本,我在使用时遇到问题。
我得到这个错误:



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> strong>Definitions.h:时,

  #includeKd_tree_patch.h
[...]
template< class SearchTraits, class Splitter_ = CGAL :: Sliding_midpoint< SearchTraits>,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>节点;
typedef typename Compact_container< Node> :: iterator Node_handle;
};

为什么Node_handle不被视为类型?



感谢您的帮助。

解决方案

您无法转发声明嵌套类型,嵌套类型 Node_handle ,模板 Kd_tree_patch 必须在之前定义 typedef。一旦你解决了,你还需要通过使用 typename 指示编译器它是一个类型:

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


I began to use templates a few weeks ago, and I'm having trouble using it. I got this error :

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> > >}’ does not name a type

while compiling this code:

"Definitions.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;
};

Why Node_handle isn't considered as a type yet ?

Thanks for your help.

解决方案

You cannot forward declare nested types, which means that to be able to use the nested type Node_handle, the template Kd_tree_patch must be defined before the typedef. Once you fix that, you will also need to instruct the compiler that it is a type through the use of typename:

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

这篇关于在模板类中定义的类型“不命名类型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆