class Q
{
friend class A;
private:
int i;
};
class A
{
virtual void Func() = 0;
};
class B : public A
{
void Func(){ Q myQ; cout << myQ.i; }
};
class C : public A
{
void Func(){ Q myQ; cout << myQ.i; }
};
Is there a way to get access to the private variable i in Q, from classes B/C, without explicitly specifying them as friends in Q?
-meZ
C++ Friend classes
This is what I''m trying to do:
Give class A two protected functions for getting and setting i.
[Resist Windows XP''s Invasive Production Activation Technology!]
[Resist Windows XP''s Invasive Production Activation Technology!]
Well, that would work.
But with several variables in Q, this way is more work than just explicitly specifying friend class B and friend class C in Q;
Are there any more "direct" ways to do it?
But with several variables in Q, this way is more work than just explicitly specifying friend class B and friend class C in Q;
Are there any more "direct" ways to do it?
A private variable can only be accessed by the class and its friends.
A protected variable can be accessed by the class, classes that inherit it and its friends.
This is the Law, your compiler will enforce it.
A protected variable can be accessed by the class, classes that inherit it and its friends.
This is the Law, your compiler will enforce it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement