Connecting Tech Pros Worldwide Forums | Help | Site Map

template functions in template class

shuisheng
Guest
 
Posts: n/a
#1: Sep 24 '06
Dear All,

I am confused about the template functions in template class. Such as I
have

template class A <class T, int n>

In side the class, I have

function A<T,nfun() and

template function void A<T,nfun <class T2, int n2>

So how to define them rightly?

template<class T, int n>
A<T, n A<T,n>::fun()
{...}

template<class T2, int n2>
template<class T, int n>
A<T, n A<T,n>::fun()
{...}

Are they right? For the first one as what I write, I think we can also
think it is a template function as A<T,nA<T,n>::fun<T,n>(), am I
right?

I appreciate you kind help!

Regards!

Shuisheng


amparikh@gmail.com
Guest
 
Posts: n/a
#2: Sep 25 '06

re: template functions in template class



shuisheng wrote:
Quote:
Dear All,
>
I am confused about the template functions in template class. Such as I
have
>
template class A <class T, int n>
>
In side the class, I have
>
function A<T,nfun() and
>
template function void A<T,nfun <class T2, int n2>
>
So how to define them rightly?
>
template<class T, int n>
A<T, n A<T,n>::fun()
{...}
This is correct.

Quote:
>
template<class T2, int n2>
template<class T, int n>
A<T, n A<T,n>::fun()
{...}
This is wrong.

The template function falls within the template class. Therefore the
template-id's for the class come first.

template<class T, int n>
template<class T2, int n2>
A<T, n A<T,n>::fun()
{...}

Quote:
>
Are they right? For the first one as what I write, I think we can also
think it is a template function as A<T,nA<T,n>::fun<T,n>(), am I
right?
>
I appreciate you kind help!
>
Regards!
>
Shuisheng
Closed Thread