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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
Thanks for the info jkr, I don't think you're ridiculous =)