Code:
class Test1
{
public:
private:
int number;
}
class Test2 : public Test1
{
public:
friend GetNumber() const {return number;}
friend SetNumber(int numb) {number = numb;}
}
The friend keyword grants access, it doesn't get them
If you want class Test2 to access Test1's private variables, you had better tell class Test1 that Test2 is a friend of it.
Code:
class Test1
{
public:
private:
int number;
friend class Test2;
};
class Test2 : public Test1
{
public:
int GetNumber() const {return number;}
void SetNumber(int numb) {number = numb;}
};
But note that you could define the variable number protected. Then you don't need to make class Test2 Test1's friend because it inherits it.