problem on partial specialization of class template

S

shuisheng

Dear All,

Assume I have a class template:

template<class T, int N = 0>
class A
{
void fun1();
void fun2();
void fun3();
void fun4();

void NRelatedFun(); // related to template parameter N.
};

Here fun1(), fun2(), fun3(), fun4() are the same. NRelatedFun() are
related to N. How to code the particular functions? I think class
template can be partial specialized. So I write as

template<class T, 1>
void A<T,1>::NRelatedFun();

But the compilor give some errors. I tried several other ways, but
still failed.

I appreicate your kind help.

Shuisheng
 
V

Victor Bazarov

shuisheng said:
Assume I have a class template:

template<class T, int N = 0>
class A
{
void fun1();
void fun2();
void fun3();
void fun4();

void NRelatedFun(); // related to template parameter N.
};

Here fun1(), fun2(), fun3(), fun4() are the same. NRelatedFun() are
related to N. How to code the particular functions? I think class
template can be partial specialized. So I write as

template<class T, 1>
void A<T,1>::NRelatedFun();

But the compilor give some errors. I tried several other ways, but
still failed.

First of all, what errors does your compiler give you? Please
start every posting attempt with reading the FAQ. Here, 5.8 is
applicable.

Second, you're specialising a member without specialising the class.
It could be the problem. Why are you declaring a member of your
A<T,1> as a function when the template specialisation can have it
as a static data member? YOu need to specialise the class first,
then show that 'NRelatedFun' is indeed a function with the specific
signature, then you can define it.

Anyway, read the FAQ 5.8.

V
 
S

shuisheng

Victor Bazarov 写é“:
First of all, what errors does your compiler give you? Please
start every posting attempt with reading the FAQ. Here, 5.8 is
applicable.

I got your message. I have read it and will follow it.
Second, you're specialising a member without specialising the class.
It could be the problem. Why are you declaring a member of your
A<T,1> as a function when the template specialisation can have it
as a static data member? YOu need to specialise the class first,
then show that 'NRelatedFun' is indeed a function with the specific
signature, then you can define it.

Thanks!.

Shuisheng
 

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
474,005
Messages
2,570,264
Members
46,860
Latest member
JeremiahCo

Latest Threads

Top