【发布时间】:2012-11-30 23:42:51
【问题描述】:
我处理的代码大致如下:
// List.h
template <typename T> class List{
template <typename TT> class Node;
Node<T> *head;
/* (...) */
template <bool D> class iterator1{
protected: Node<T> this->n;
public: iterator1( Node<T> *nn ) { n = nn }
/* (...) */
};
template <bool D> class iterator2 : public iterator1<D>{
public:
iterator2( Node<T> *nn ) : iterator1<D>( nn ) {}
void fun( Node<T> *nn ) { n = nn; }
/* (...) */
};
};
(如需上述具体代码,请参考我的previous question)
// Matrix.h
#include "List.h"
template <typename T>
class Matrix : List<T> {
/* (...) - some fields */
class element {
supervised_frame<1> *source; // line#15
/* (...) - some methods */
};
};
我在 g++ 中收到以下错误:
In file included from main.cpp:2:
Matrix.h:15: error: ISO C++ forbids declaration of ‘supervised_frame’ with no type
Matrix.h:15: error: expected ‘;’ before ‘<’ token
【问题讨论】:
-
这里没有足够的代码来查明错误。但是,您猜测一下,您需要转发声明
supervised_frame<int>。 -
@Yuushi 请参考提供的链接。我在上面的代码中包含了 List.h,并且在其中定义了 supervised_frame。
-
谁赞成这个问题,为什么?这完全是荒谬的。 @infoholic_anonymous:请看sscce.org;让你需要帮助的人做所有的工作是没有效率的。
-
@ildjarn 这个标题在我看来非常清楚。不过,他确实应该包含
List的简短定义。 -
@Pubby 谢谢你的评论,我已经按照你的建议做了
标签: c++ templates inheritance visibility nested-class