1

我处理的代码大致如下:

// 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; }
        /* (...) */
    };
};

(如果需要上述代码的确切代码,请参考我之前的问题

// 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 ‘&lt;’ token
4

2 回答 2

2

我相信Matrix<T>::elementclass 与 class 无关List<T>。所以我认为你应该有typename List<T>::template supervised_frame<1>

于 2012-12-13T06:04:52.123 回答
2

和你之前的问题类似——Use typename List<T>::supervised_frame<1> *source;This是因为supervised_frame<1>是依赖类型,即依赖于模板参数T

于 2012-12-13T06:05:06.763 回答