Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Template specializations and namespaces

Reply
Thread Tools

Template specializations and namespaces

 
 
Juha Nieminen
Guest
Posts: n/a
 
      12-12-2011
I'm wondering why this seems to be illegal C++:

namespace Hops { template<bool> void foo(); }
template<> void Hops::foo<false>() { std::cout << "false\n"; }
template<> void Hops::foo<true>() { std::cout << "true\n"; }

Both gcc and clang give errors, saying that the template specializations
are in a "different namespace" than the template declaration.

(Yes, I know that the problem can be solved by putting the
specializations explicitly inside the namespace. However, this seems
to be an odd special rule. Compilers do not seem to have any problem
in compiling this if you enable a proper extension. Why does this rule
exist?)
 
Reply With Quote
 
 
 
 
Andrew Tomazos
Guest
Posts: n/a
 
      12-13-2011
On Dec 12, 3:23*pm, Juha Nieminen <(E-Mail Removed)> wrote:
> * I'm wondering why this seems to be illegal C++:
>
> namespace Hops { template<bool> void foo(); }
> template<> void Hops::foo<false>() { std::cout << "false\n"; }
> template<> void Hops::foo<true>() { std::cout << "true\n"; }
>
> * Both gcc and clang give errors, saying that the template specializations
> are in a "different namespace" than the template declaration.
>
> * (Yes, I know that the problem can be solved by putting the
> specializations explicitly inside the namespace. However, this seems
> to be an odd special rule. Compilers do not seem to have any problem
> in compiling this if you enable a proper extension. Why does this rule
> exist?)


http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
non-class template params in partial specializations Samee Zahur C++ 1 04-29-2005 01:23 PM
Same template arguments, different specializations Imre C++ 1 02-21-2005 12:42 PM
Order of template specializations Thomas Matthews C++ 0 02-26-2004 08:55 PM
template specialization hides other specializations-msvc6 Tom Richardson C++ 1 12-19-2003 05:05 PM
virtual inheritance problem with class template specializations Tseng, Ling-hua C++ 0 12-08-2003 08:53 AM



Advertisments