Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

friend function accessing protected members of base class

0 views
Skip to first unread message

Rahul

unread,
Apr 7, 2008, 8:56:03 AM4/7/08
to
Hi Everyone,

I have the following code,

class sample
{
protected : int i;
private: int j;
public: sample()
{
i = 5;
j = 10;
}
};

class two : public sample
{
public: two()
{
i = 10;
}
friend void test()
{
i = 111;
}
};

And i get an error saying test() cannot access two::sample::i;
Is there any was for the friend function test() to access the
protected members?

Thanks in advance ! ! !

Rahul

unread,
Apr 7, 2008, 9:04:55 AM4/7/08
to

oops, not doing the write way, found the mistake

friend void test()
{
two obj;
obj.i = 111;
}

0 new messages