PC Review


Reply
Thread Tools Rate Thread

Defining template method specialization outside of template class definition

 
 
Michael Stembera
Guest
Posts: n/a
 
      24th Nov 2003
I have a case of a very simple template class w/ a
template method. If I define a specialization of the
method outside the body of the template class it does not
compile. Here is a tiny example to illustrate.


template<typename T>
class C
{
public:
template<int N> bool foo(void);
template<> bool foo<1>(void);
};

template<typename T>
template<int N>
bool C<T>::foo(void)
{
return N > 0;
}

template<typename T>
template<>
bool C<T>::foo<1>(void)
{
return false;
}
// error C2768: 'C<T>::foo' : illegal use of explicit
template arguments


However, if I define the specialization inside

template<typename T>
class C
{
public:

template<int N> bool foo(void)
{
return N > 0;
}

template<> bool foo<1>(void)
{
return false;
}
};

it compiles fine. BTW, the non specialized version can
be defined inside or outside of the class and it makes no
difference either way. Also, if the class itself is NOT
a template class both versions compile fine.

Is this a user or compiler or C++ standard issue? I'm
using MS VC++ 7.1.3088.

Thanks in advance,
Michael Stembera
 
Reply With Quote
 
 
 
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      25th Nov 2003
Michael Stembera wrote:

> Is this a user or compiler or C++ standard issue? I'm
> using MS VC++ 7.1.3088.


C++ standard issue - the standard prohibits this kind of specialization.

> However, if I define the specialization inside
> it compiles fine.


According to Comeau, it shouldn't compile inside the class either.

-cd


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Template specialization and partial specialization Alfonso Morra Microsoft VC .NET 4 27th Jul 2005 04:18 PM
Template specialization Vladimir Nesterovsky Microsoft VC .NET 1 13th Jul 2004 11:01 AM
BUG VC7.1: in class friend template function definition does not have access to the class's template parameters Maxim Yegorushkin Microsoft VC .NET 5 6th Jun 2004 02:56 AM
error C2912: explicit specialization; ... is not a specialization of a function template JohnPantango@hotmail.com Microsoft VC .NET 1 8th May 2004 07:30 PM
template, specialization and header Thibault Microsoft VC .NET 1 12th Aug 2003 03:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:05 PM.