Link to home
Start Free TrialLog in
Avatar of oxygen_728
oxygen_728

asked on

C++ Friend -- Friend Class - Can I make all its sub-classes also friends automatically?

Class A is a master "grandparent" class.
Class B inherits from Class A.
Class C inherits from Class B.

Class Tester{
private:
  int private_int;
  friend class A;
}

Is there some way to give Classes B and C access to Class Tester's private members without also including "friend class B;" and "friend class C;"?

I would like the subclasses of Class A to inherit Class A's friend status with other classes.

Thanks in advance for your time.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oxygen_728
oxygen_728

ASKER

I think it is completely ridiculous that there isn't a transitive version.

Thanks for the info jkr, I don't think you're ridiculous =)
jkr is my hero
Actually, it is fine the way it is. IMO friends should be used really sparsely, since it to some extent breaks OO principles. Yet sometimes you won't be able to completely avoid it.