recursiveness on template member function of a template class

A

AG

Hi all,

I am trying to do that, but it does not compile. I am not even sure this is
possible.
I have read somewhere that specialization inside a template class is not
without specializing the class itself, but couldn't verify it into the
standard.
Help would be appreciated.

Alexandre.

#define N 20

template<class T> class A
{
public:
template<int D> void f(T *a);
};

template<class T> template<int D> void A<T>::f<D>(T *a)
{
int i;
for(i=0;i<9;i++)
a[i+1]+=a;
f<D-1>(a+10);
}

template<class T> template<> void A<T>::f<0>(T * a)
{
int i;
for(i=0;i<9;i++)
a[i+1]+=a;
}

int main()
{
A<int> myObject;
int tab[N];
myObject.f<1>(tab);
return 0;
}
 
A

amparikh

Hi all,

I am trying to do that, but it does not compile. I am not even sure this is
possible.
I have read somewhere that specialization inside a template class is not
without specializing the class itself, but couldn't verify it into the
standard.
Help would be appreciated.

Alexandre.

#define N 20

template<class T> class A
{
public:
template<int D> void f(T *a);

};

template<class T> template<int D> void A<T>::f<D>(T *a)
{
int i;
for(i=0;i<9;i++)
a[i+1]+=a;
f<D-1>(a+10);

}

template<class T> template<> void A<T>::f<0>(T * a)
{
int i;
for(i=0;i<9;i++)
a[i+1]+=a;

}


This is not possible. You need to first specialize A, and then have a
specialization for f.
int main()
{
A<int> myObject;
int tab[N];
myObject.f<1>(tab);
return 0;



}- Hide quoted text -

- Show quoted text -
 
V

Victor Bazarov

AG said:
[..]
I have read somewhere that specialization inside a template class is
not without specializing the class itself, but couldn't verify it
into the standard.

[temp.expl.spec]/18, the first sentence, after "except".

V
 
A

AG

Victor Bazarov said:
AG said:
[..]
I have read somewhere that specialization inside a template class is
not without specializing the class itself, but couldn't verify it
into the standard.

[temp.expl.spec]/18, the first sentence, after "except".
Thank you. I guess I don't have a recent version of the standard. (In my
draft version of the 1996 standard, this /18 doesn't exist).

AG.
 
V

Victor Bazarov

AG said:
Victor Bazarov said:
AG said:
[..]
I have read somewhere that specialization inside a template class is
not without specializing the class itself, but couldn't verify it
into the standard.

[temp.expl.spec]/18, the first sentence, after "except".
Thank you. I guess I don't have a recent version of the standard. (In
my draft version of the 1996 standard, this /18 doesn't exist).

Get the next draft (if you don't want to get the official version), it's
downloadable from the Committee page:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2315.pdf

Note, that in it it's paragraph 19, not 18.

V
 

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

No members online now.

Forum statistics

Threads
474,290
Messages
2,571,453
Members
48,129
Latest member
DianneCarn

Latest Threads

Top