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

recursiveness on template member function of a template class

P: n/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 Tclass A
{
public:
template<int Dvoid f(T *a);
};

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

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

int main()
{
A<intmyObject;
int tab[N];
myObject.f<1>(tab);
return 0;
}
Aug 7 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Aug 7, 9:25 am, "AG" <a...@tb.frwrote:
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 Tclass A
{
public:
template<int Dvoid f(T *a);

};

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

}

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

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

}- Hide quoted text -

- Show quoted text -

Aug 7 '07 #2

P: n/a
AG wrote:
[..]
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 7 '07 #3

P: n/a
AG
"Victor Bazarov" <v.********@comAcast.neta écrit dans le message de news:
f9**********@news.datemas.de...
AG wrote:
>[..]
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.
Aug 8 '07 #4

P: n/a
AG wrote:
"Victor Bazarov" <v.********@comAcast.neta écrit dans le message de
news: f9**********@news.datemas.de...
>AG wrote:
>>[..]
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/wg...2007/n2315.pdf

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

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 8 '07 #5

P: n/a
AG
Note, that in it it's paragraph 19, not 18.
thanks,

AG.
Aug 9 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.