🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.oodesign
4 messages
4 total messages Started by Wiljo Thu, 24 Feb 2005 09:24
How to make a template class friend of another class.
#39
Author: Wiljo
Date: Thu, 24 Feb 2005 09:24
35 lines
1697 bytes
Hi all,

I have a class with protected and/or private members that need to be accessed by 
a close relative but template class. Normally one would make the second class 
friend of the first, but when this second class is a template, how can I 
accomplish it then?

//#
//# class A
//#
class A
{
public:

friend class B;		//* This wont work, because class B is template

private:
	void privateFunction();
};
//#
//# template class B
//#
template <class XType>
class B
{
public:
	void myFunction( A *ptrA )
	{ ptrA->privateFunction(); }
};
//#
//#

Any ideas would be greatly appreciated.

Wiljo.
Re: How to make a template class friend of another class.
#40
Author: Thomas Maeder [TeamB]
Date: Thu, 24 Feb 2005 17:52
37 lines
1939 bytes
Wiljo <invalid@invalid.address> writes:

> I have a class with protected and/or private members that need to be
> accessed by a close relative but template class. Normally one would
> make the second class friend of the first, but when this second class
> is a template, how can I accomplish it then?

Do you want all specializations of B to be friends of A, or just one
particular specialization?


> //#
> //# class A
> //#
> class A
> {
> public:
>
> friend class B;		//* This wont work, because class B is template
>
> private:
> 	void privateFunction();
> };
> //#
> //# template class B
> //#
> template <class XType>
> class B
> {
> public:
> 	void myFunction( A *ptrA )
> 	{ ptrA->privateFunction(); }
> };
> //#
> //#

What's the point in making B a template?
Re: How to make a template class friend of another class.
#43
Author: Wiljo
Date: Mon, 07 Mar 2005 10:51
22 lines
1965 bytes
Thomas Maeder [TeamB] wrote:

> Do you want all specializations of B to be friends of A, or just one
> particular specialization?
> 
Yes, I want all specializations of B to be friend of A.
> 
> What's the point in making B a template?

Well I oversimplified the example code a bit too much, and I didn't make sense 
anymore. B needs to be template, because it handles several different object 
types. The one thing they have in common is that they are all derived from class 
A. A has private functionality, that I don't wan't to access directly from any 
derived class, hence the private specifier. I DO wan't to access these private 
functionality from the template class though. Hence my question.

I solved the problem by making a base class for the template class B. This base 
class can be friend of A without any problem.

Thanks anyway.

Wiljo.
Re: How to make a template class friend of another class.
#44
Author: Thomas Maeder [TeamB]
Date: Mon, 07 Mar 2005 16:35
5 lines
1354 bytes
Wiljo <invalid@invalid.address> writes:

This is the wrong newsgroup for this topic.

Cf. my answer over in .cppbuilder.language
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads