This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc4, namespace and template specialization problem


On Mon, Apr 04, 2005 at 12:15:07PM +0200, tbp wrote:

> On Apr 4, 2005 11:54 AM, Nathan Sidwell <nathan@codesourcery.com> wrote:
> > > Am i missing something obvious?
> > well, not 'obvious', but that is what [14.7.3]/2 says.
> I especially don't quite get why specialization have to be defined
> that way when non specialized version don't have to, ie that is legit:
> namespace dummy {
> 	struct foo {
> 		template <int i> void f();
> 	};
> } 
> template<int i> void dummy::foo::f() { }

That's not an explicit specialisation, so the same rules don't apply.
That's just a definition of the primary template.

[14.7.3]/2 says that the *declaration* of an explicit specialisation
must appear in the same namespace. The *definition* can appear in an
enclosing namespace (as with your example above,) so you can do this:

    namespace dummy {
            struct foo {
                    template <int i> void f() {}
            };
            template<> void foo::f<666>();        // declare specialisation
    }
    template<> void dummy::foo::f<666>() {}       // define specialisation

Hope that helps,

jon

-- 
Prediction is very difficult, especially about the future.
	- Niels Bohr


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]