Ok, I wrote it differently:
c0 has my_link, which c1 needs to be able to modify, within it's
constructor.
Once again, why do_other is able to modify obj.my_link
but c1 constructor is not. The rationale behind standard?
I do understand that c0 is a implicit friend of c0, and c1 is
not implicit friend of c0.
But I don't get the benefit of this arrangement. Both situations
should be the same.
PS. I guess there isn't any way to revoke implicit friendness from a class
to itself, or is there?
(This has nothing to do with virtual functions)
Topi
#include <stdio.h>
class c0;
class c1;
class c0
{
c0 *my_link;
protected:
void add_link(c0 &obj)
{
my_link=&obj;
}
void do_other(c0 &obj)
{
add_link(obj);
obj.add_link(*this); // This is ok, as c0 is a firend of c0.
}
};
class c1: public c0
{
int x;
public:
c1(c0 &obj,int xx)
{
x=xx;
if(x==0)
{
add_link(obj);
obj.add_link(*this); // This doesn't compile, as c1 is not a friend of
c0.
}
else
{
add_link(*this);
obj.add_link(obj); // This doesn't compile either.
}
}
};
class c2: public c0
{
int x;
};
int main(void)
{
c2 v2;
c1 v1(v2,2);
}