Am new to cpp. Generally, friend function could access private and protected members of the class but when I tried to use friend function in derived class am observing weired behavior..
class first
{
int a;
};
class second : public first
{
public:
friend void hai ( second );
};
void hai ( second s )
{
printf("%d",s.a); // It says compilation error
}
void main()
{
second s;
hai(s);
}
If I make a to public, it works fine.
Could somebody clear me, why shouldn't I access a if its in base private scope.
Regards Prasath S.