By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

problem on partial specialization of class template

P: n/a
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

Sep 29 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
shuisheng wrote:
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,1as 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 29 '06 #2

P: n/a

Victor Bazarov 写道:
shuisheng wrote:
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.
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,1as 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

Sep 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.