template functions in template class

S

shuisheng

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,n> fun() and

template function void A<T,n> fun <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,n> A<T,n>::fun<T,n>(), am I
right?

I appreciate you kind help!

Regards!

Shuisheng
 
A

amparikh

shuisheng said:
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,n> fun() and

template function void A<T,n> fun <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.

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()
{...}
 

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

Forum statistics

Threads
474,005
Messages
2,570,264
Members
46,860
Latest member
JeremiahCo

Latest Threads

Top