继承类中嵌套类的可见性

时间:2012-12-13 05:56:50

标签: c++ templates inheritance visibility nested-class

我所处理的代码大致如下:

// 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

2 个答案:

答案 0 :(得分:2)

我认为Matrix<T>::element课程与课程List<T>无关。所以我认为你应该有typename List<T>::template supervised_frame<1>

答案 1 :(得分:2)

与您之前的问题类似 - 使用typename List<T>::supervised_frame<1> *source;这是因为supervised_frame<1>是一种依赖类型,即它依赖于模板参数T