Isn't the friend
function supposed to access everything that is in Base
class and Derived
class? class Derived: public Base
-> everything that is in private
in Base
is now public
inside the class derived.
class Base
{
private:
int x;
};
class Derived : public Base
{
int y;
public:
void SetY(int value);
void friend SetX(Derived &d);
};
void SetX(Derived &d)
{
d.x = 100; // Why is this a problem?
// Isn't Base supposed to be public now that is inherited?
}
int main()
{
Derived d;
SetX(d);
}