[LC++]Pure base class as a friend
lsim_au at yahoo.com.au
Fri Sep 7 13:35:07 UTC 2001
On Fri, 7 Sep 2001 12:50, Mark Phillips wrote:
> 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
Could you make methods in manipulatorTy that do the maninulating at a
low level, then in the sub classes use these methods to do the work.
That way as long as the low level access methods are protected, you get
something like what you are sudgesting.
> 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?
Sounds right, sorry.
> 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?
'Such is Life' - Ned Kelly, just before he was hanged.
She is descended from a long line that her mother listened to.
-- Gypsy Rose Lee
More information about the tuxCPProgramming