This is the mail archive of the gcc-help@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: specialize a template function out of its namespace



On 03.06.2008, at 07:26, Yunior Peralta González wrote:


Hi all.

I have the following problem:

namespace test
{
   class A
   {
       template <typename T>
       void foo(T &);
   };
}

//specialize the function out of namespace test
template <> test::A::foo<int>(int & a)
{
   //do something with a
}

if on the contrary I put it this way:

namespace test
{
   class A
   {
       template <typename T>
       void foo(T &);
   };

   //specialize the function inside namespace test
   template <> A::foo<int> (int & a)
   {
       //do something with a
   }
}

it works ok.

How can I use the first form without errors?

You just can't...
which is sometimes a pain (e.g., for generating code by macros), but thats how C++ is.


Daniel


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