can a class grant access to a friend method of friend class?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2007
Posts: 32
Reputation: tnvkrishna is an unknown quantity at this point 
Solved Threads: 0
tnvkrishna's Avatar
tnvkrishna tnvkrishna is offline Offline
Light Poster

can a class grant access to a friend method of friend class?

 
0
  #1
Nov 7th, 2007
title was self explanatory..

i repeat ..

can a class allow a friend method of a friend class to use it's protected or private members

oh yes one more,

can a friend method of a derived class use base class's protected members

i am new to this type of concept
please help

thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,619
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: can a class grant access to a friend method of friend class?

 
0
  #2
Nov 7th, 2007
>can a class allow a friend method of a friend class to use it's protected or private members
Just because you're my friend doesn't mean your other friends are also my friends.

>can a friend method of a derived class use base class's protected members
If you're my child, your friends aren't necessarily my friends.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: can a class grant access to a friend method of friend class?

 
0
  #3
Nov 8th, 2007
>> can a friend method of a derived class use base class's protected members
friend functions have the same access rights as the members of the class. a derived class can access (only) inherited protected members of the base class. if a derived class can access the base class's protected members, friends of the derived class can access them too. and if a derived class cannot access the base class's protected members (because it has not inherited them), friends of the derived class also cannot access them. for example:
  1. struct base_class
  2. {
  3. protected: int protected_member ;
  4. };
  5.  
  6. struct derived_class : base_class
  7. {
  8. void member_function( derived_class& derived, base_class& base )
  9. {
  10. derived.protected_member = 9 ; // ok, inherited by derived_class
  11. derived.base_class::protected_member = 9 ; // also ok, inherited
  12. base.protected_member = 9 ; // error, not inherited by derived_class
  13. }
  14. friend inline void friend_function( derived_class& derived,
  15. base_class& base )
  16. {
  17. derived.protected_member = 9 ; // ok, inherited by derived_class
  18. derived.base_class::protected_member = 9 ; // also ok, inherited
  19. base.protected_member = 9 ; // error, not inherited by derived_class
  20. }
  21. };
Last edited by vijayan121; Nov 8th, 2007 at 3:51 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC