473,396 Members | 1,749 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,396 software developers and data experts.

recursiveness on template member function of a template class

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
5 1151
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
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
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
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
AG
Note, that in it it's paragraph 19, not 18.
thanks,

AG.
Aug 9 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gert Van den Eynde | last post by:
Hi all, A beginners question.... I've got a template class template <class T> classA {...} In an other class, I want to pass a pointer to an instance of classA as a function argument....
0
by: Chris F Clark | last post by:
In our C++ project we have some internal bug reporting macros that we use to get useful information when the program does something unexpected. Essentially at the point of the error, we invoke an...
7
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
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>
2
by: pookiebearbottom | last post by:
Just trying to learn some things about templates. Was wondering how boost::tupple really works, but the headers were a bit confusing to me. I know you get do something like the following, just...
3
by: toton | last post by:
Hi, I want to specialize template member function of a template class . It is creating some syntax problem .... Can anyone say how to do it ? The class is something like this template<typename...
12
by: stefan.bruckner | last post by:
Hi, I am looking for a way to achieve the following. I've tried a couple of things, but they all ended up being too complicated: I have a templated class A. I want another class B to be able...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.