Afficher un message
Vieux 07/04/2008, 15h04   #2
Rahul
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: friend function accessing protected members of base class

On Apr 7, 5:56 pm, Rahul <sam_...@yahoo.co.in> wrote:
> 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 ! ! !


oops, not doing the write way, found the mistake

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

  Réponse avec citation
 
Page generated in 0,05259 seconds with 9 queries