|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 ! ! ! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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; } |
|
![]() |
| Outils de la discussion | |
|
|