I do not know if the following example is considered valid code. I do not have a copy of the standard. The following code fails with g++-3.4 (GCC) 3.4.4 20050314 (prerelease) (Debian 3.4.3-12). error messages: test.cpp:28: error: invalid explicit specialization before '>' token test.cpp:28: error: explicit specialization in non-namespace scope `struct heap<_T>' test.cpp:28: error: enclosing class templates are not explicitly specialized test.cpp:28: error: template parameters not used in partial specialization: test.cpp:28: error: `_T' test.cpp:31: error: `template<class _T> struct heap' used without template parameters test.cpp:31: error: `pointer' was not declared in this scope test.cpp:31: error: template argument 1 is invalid test.cpp:31: error: invalid type in declaration before ';' token The error in line 28 occurs because the template is specialized in that scope but declared in the base class. The error in line 31 seems to be a lookup failure. Unless redefined 'pointer' should be inherited and visible. --- test.cpp template<typename _T> class wrapper { public: wrapper(_T t): _M_t(t) {} operator _T& () { return _M_t; } private: _T _M_t; }; struct container { struct pointer {}; struct forward {}; struct backward {}; struct bidirectional {}; struct randomaccess {}; template<typename _T> struct iterator; }; template<typename _T> struct heap: container { typedef _T value_type; // does not make a difference // template<typename _U> struct iterator; template<> struct iterator<pointer>: wrapper<value_type *> {}; }; heap<int>::iterator<heap::pointer> p;
-- Summary: Templates and sub types are not inherited in g++ Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sven at clio dot in-berlin dot de CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i486-linux GCC host triplet: i486-linux GCC target triplet: i486-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21543