[LC++]Pure base class as a friend

Mark Phillips mark at austrics.com.au
Fri Sep 7 13:17:06 UTC 2001


Suppose I have a class "pointTy" which stores a point on a sphere.  And
suppose I have a pure base class "manipulatorTy" which allows the
manipulation of these points.  The idea is that there might be various
different types of manipulation, expressed via derived classes from this
base class.  What I would like to be able to do, is say manipulatorTy
is a friend of pointTy.  So that any manipulator would be able to
change private members of pointTy.  But my understanding is that
only the base class would be a friend of pointTy.  Any classes derived
from manipulatorTy would not be friends unless they were each explicitly
declared friend (which is not a good idea).  Am I right about this?

At the moment, the only way around my dilemma is to change some of the
pointTy private members into public members.  But I'd prefer not to do
this if I can.

I could make manipulatorTy a derivation of pointTy, and make the
internals of pointTy "protected", but this won't work because I want
manipulators to be able to work on more than one point, and to change
the points they are working on.

Any ideas?



More information about the tuxCPProgramming mailing list