Topic: Proposal: protected friends


Author: johnw@jove.acs.unt.edu (John Robert Williams)
Date: 1995/04/16
Raw View
I got this idea after having to confront a problem where I have two
abstract bases, Bitmap and Screen, and I want to make all Screens be
friends of all Bitmaps, so I don't have to use a cheesey solution that
violates encapsulation. My proposal is to make a type of friendship that
IS inherited:

class Screen {...};
class Bitmap {public friend Screen;...}; /* All bitmaps are friends of
                                            all screens. */
...or...
class Bitmap {protected friend Screen;...}; /* Either all Bitmaps are
friends of Screen or all Screens are friends of Bitmap...that's one that
would take some consideration... */

We could then go further and say that friendship is private by default in
classes and public in structs...

--
John Williams  <johnw@jove.acs.unt.edu>
"Pascal is Pascal is Pascal is dog meat."
  -- M. Devine and P. Larson, Computer Science 340