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

M

m0shbear

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.
 
N

Nobody

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) {
 
P

Paul

m0shbear said:
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.
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top