c++ - g++ doesn't compile certain nested templates -
when break defined, g++ 4.7.2 not compile following, think valid c++. compile break defined if a<u> tmp
changed else, a<int> tmp
- while makes minimal test case here work, it's no in actual application. there here not legal c++?
template <typename t> class b { }; template <typename t> class { public: template <typename u> b<u> *alloc_b( ); }; template <typename t> template <typename u> b<u> *a<t>::alloc_b( ) { return new b<u>( ); } #ifdef break template <typename t> class c { public: template <typename u> void x(b<u> &b) { a<u> tmp; b<u> *tmp2; tmp2 = tmp.alloc_b<u>( ); delete tmp2; } }; #endif int main( ) { a<int> a; b<float> *bp = a.alloc_b<float>( ); delete bp; #ifdef break c<int> c; b<float> b; c.x(b); #endif }
the alloc_b
function template dependent name. must call so:
tmp2 = tmp.template alloc_b<u>( );
that's problem, , why works when use a<int>
, because type no longer depends on template argument u
.
Comments
Post a Comment