From: gao_bolin on 6 Mar 2006 13:32 The following code doesn't compile with g++ 4.0.2: -- #include <iostream> template < typename T > class A {}; template < typename T > class B { public: struct C; }; template < typename T > struct B<T>::C { void foo() { std::cout << "C" << std::endl; } }; template < typename T > struct B<A<T> >::C { void foo() { std::cout << "C spec" << std::endl; } }; int main(int argc, char * argv[]) { B<A<double> >::C c; c.foo(); return 0; } -- it fails with the following message: main.cpp:22: error: qualified name does not name a class before '{' token (line 22 is the line following "struct B<A<T> >::C"). Am I doing something wrong when partially specializing member class C? Or is it something that is forbidden by the standard? If so, what could be the reason? Thx G. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: amparikh on 7 Mar 2006 19:47 gao_bolin(a)voila.fr wrote: > The following code doesn't compile with g++ 4.0.2: > > -- > > #include <iostream> > > template < typename T > > class A {}; > > template < typename T > > class B > { > public: > struct C; > }; > > template < typename T > > struct B<T>::C > { > void foo() { std::cout << "C" << std::endl; } > }; > > template < typename T > > struct B<A<T> >::C > { > void foo() { std::cout << "C spec" << std::endl; } > }; > > int main(int argc, char * argv[]) > { > B<A<double> >::C c; > c.foo(); > return 0; > } > > -- <snip> You need to first specialize B for A<T> and then use specialization for foo for that B. Here. template < typename T > class A {}; template < typename T > class B { public: struct C; }; template < typename T > struct B<T>::C { void foo() { std::cout << "C" << std::endl; } }; template<typename T> class B < A<T> > { public: struct C; }; template < typename T > struct B< A<T> >::C { void foo() { std::cout << "C spec" << std::endl; } }; int main(int argc, char * argv[]) { B<A<double> >::C c; c.foo(); return 0; } [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: no appropriate default constructor available Next: VC++ compiler bug? |