Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is there aA correct way of specializing member functions of template classes?

Reply
Thread Tools

Is there aA correct way of specializing member functions of template classes?

 
 
m0shbear
Guest
Posts: n/a
 
      03-01-2011
Suppose I have the following:
foo.h--
template <class T>
class Foo {
T bar(const T&);
};

foo.cpp--
#include "foo.h"
int Foo<int>::bar(const int& x) {
....
return ...;
}

The compile fails with " error: too few template-parameter-lists" (g++
4.5).

Is there a correct way to properly specialize such member functions?
As there is a small, finite set of T to be used, I want to specialize
for all T.
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      03-01-2011
On Mon, 28 Feb 2011 21:30:14 -0800, m0shbear wrote:

> int Foo<int>::bar(const int& x) {
> ...
> return ...;
> }
>
> The compile fails with " error: too few template-parameter-lists" (g++
> 4.5).
>
> Is there a correct way to properly specialize such member functions?


template<>
int Foo<int>::bar(const int& x) {

 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      03-01-2011

"m0shbear" <> wrote in message
news:a2443ccb-a350-44c2-bbd7-...
> Suppose I have the following:
> foo.h--
> template <class T>
> class Foo {
> T bar(const T&);
> };
>
> foo.cpp--
> #include "foo.h"
> int Foo<int>::bar(const int& x) {
> ...
> return ...;
> }
>
> The compile fails with " error: too few template-parameter-lists" (g++
> 4.5).
>
> Is there a correct way to properly specialize such member functions?
> As there is a small, finite set of T to be used, I want to specialize
> for all T.
>


AFAIK you cannot specialise the member function without specialising the
whole class.
..

 
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
overloading non-template member functions with template member functions Hicham Mouline C++ 1 04-24-2009 07:47 AM
overloading non-template member functions with template member functions Hicham Mouline C++ 0 04-23-2009 11:42 AM
partially specializing member functions of a template class Rahul C++ 8 07-16-2007 02:22 PM
Specializing Member Function Template of Class Template? Simon G Best C++ 2 12-29-2006 12:32 PM
Trouble specializing a member function in a template class Jeff C++ 2 11-20-2003 04:39 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57