473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem on partial specialization of class template

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
2 1661
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
4
by: TT \(Tom Tempelaere\) | last post by:
Comeau compiler complains (too few arguments for class template "B") at line *** #include <memory> template<typename T, size_t n> struct A {}; template<typename T, size_t n> struct B;
13
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under Solaris: class A { }; class B { }; ...
1
by: BekTek | last post by:
I'm still confused about the template partial specialization which is used in many libraries.. due to lack of introduction for beginner.. Could you tell me about that in short? Thanks in...
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
4
by: Alfonso Morra | last post by:
Does VC 7.1 support template specialization and partial specialization ?
6
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
7
by: aaragon | last post by:
Hi everyone, The idea is quite simple: generate a container with random values in it. For that, I decided to create a class that I called RandomContainer that inherits from a container (with...
10
by: jason.cipriani | last post by:
I never seem to be able to get this right. Here I have some code: template <typename T, int Nclass A { void f (T); }; template <typename Tvoid A<T,1>::f (T) { } template <typename Tvoid...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.