Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11615

Re: How to avoid splitting namespace scope?

From "Bo Persson" <bop@gmb.dk>
Newsgroups comp.lang.c++
Subject Re: How to avoid splitting namespace scope?
Date 2011-11-19 10:55 +0100
Message-ID <9ipcnjFg7oU1@mid.individual.net> (permalink)
References <1e180097-a703-4bc9-bf7d-b51afaf245ea@a5g2000vbb.googlegroups.com>

Show all headers | View raw


Jayden Shui wrote:
> Hello All,
>
> I give every class a tag by specialize the following template
> function:
>
> template<class T>
> std::string Tag();
>
> However, when working on a class in a namespace such as
>
> namespace S
> {
>    class A { /*codes for A*/ };
>
>    template<>
>    std::string Tag<A>()
>    {
>         return "A";
>    }
>
>    // other codes
> }
>
> The compiler give an error. I have to specialize it in global scope
> like
>
> namespace S
> {
>    class A { /*codes for A*/ };
> }
>
> template<>
> std::string Tag<S::A>()
> {
>     return "A";
> }
>
> namespace S
> {
>    // other codes
> }
>
> I don't want split the namespace scope by the tag specialization.
> Anyway I can make it work without the splitting?
>

No really. You cannot specialize a template from one namespace inside 
another namespace.


Bo Persson

Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

How to avoid splitting namespace scope? Jayden Shui <jayden.shui@gmail.com> - 2011-11-18 18:58 -0800
  Re: How to avoid splitting namespace scope? laird@lbreyer.com - 2011-11-18 20:55 -0800
    Re: How to avoid splitting namespace scope? Jayden Shui <jayden.shui@gmail.com> - 2011-11-18 21:27 -0800
      Re: How to avoid splitting namespace scope? laird@lbreyer.com - 2011-11-18 22:19 -0800
  Re: How to avoid splitting namespace scope? "Bo Persson" <bop@gmb.dk> - 2011-11-19 10:55 +0100

csiph-web