how to declare friend for template class ?

S

slocum

how to declare friend for template class ?

class A
{
public:
.....
private:
.....

friend class B ????????
}

template <class T>
class B
{
}
 
M

Martin York

how to declare friend for template class ?

class A
{
public:
.....
private:
.....

friend class B ????????

}

template <class T>
class B
{

}

You can't.
Though you can defined friends for particular versions of B.

template<typename T>
class B
{
};

class A
{
friend class B<int>;
friend class B<float>;
friend class B<MyType>;
// etc..
};
 
S

slocum

And what about this way ??

template <typename T>
class B
{

};

template <typename T>
class A
{
friend class B<T>;

};
 
B

Brian Tyler

You can't.
Though you can defined friends for particular versions of B.

template<typename T>
class B
{
};

class A
{
friend class B<int>;
friend class B<float>;
friend class B<MyType>;
// etc..
};

That is completely untrue


template<class T> class B
{
// Stuff
};

class A
{
template <class> friend class B;
};

makes B a friend irrespective of the type of it's template parameter.

Brian.
 
M

Martin York

That is completely untrue

class A
{
template <class> friend class B;

};

makes B a friend irrespective of the type of it's template parameter.

Live and learn.
 

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
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top