sorry i made a mistake. This is legal code:
class base
{
private:
int a;
friend class derived;
}
class derived : public base
{
public:
derived() { a=0; }
}
the error i had was because i was trying to initialise a member of a base class ('a') in a derived classes initialisation list (which as we all know is wrong).
User Profile
Collapse
-
this is actually legal c++ code. my problem was that I linking against an outdated library!
the derived class inherits the base class and is a friend of the base class so can access its member variables. (but it doesn't inherit the friend itself, which in this case would make it a friend of itself!)Leave a comment:
-
Derived class friend of base class
Hi all,
Why in the following example can the derived class not see the base class:
class base
{
private:
int a;
friend class derived;
}
class derived : public base
{
public:
derived() : a(0) { ; } //error a is private
}
why doesn't the friend declaration allow access to a? is it because it is not inherited...
No activity results to display
Show More
Leave a comment: