| | |
can a class grant access to a friend method of friend class?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
>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.
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.
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
>> 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:
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:
c++ Syntax (Toggle Plain Text)
struct base_class { protected: int protected_member ; }; struct derived_class : base_class { void member_function( derived_class& derived, base_class& base ) { derived.protected_member = 9 ; // ok, inherited by derived_class derived.base_class::protected_member = 9 ; // also ok, inherited base.protected_member = 9 ; // error, not inherited by derived_class } friend inline void friend_function( derived_class& derived, base_class& base ) { derived.protected_member = 9 ; // ok, inherited by derived_class derived.base_class::protected_member = 9 ; // also ok, inherited base.protected_member = 9 ; // error, not inherited by derived_class } };
Last edited by vijayan121; Nov 8th, 2007 at 3:51 am.
![]() |
Similar Threads
- adding to a dynamic array size... (Java)
- Tutorial: An introduction to Test Driven Development (Computer Science)
- grant access (C++)
- couple of questions about encapsulation (C++)
- How to access a variable of a diff class (C++)
- accessing private data members (C++)
- Classes (C++)
Other Threads in the C++ Forum
- Previous Thread: Need help reading and writing to file
- Next Thread: Complete Noob. Reading/Writing to/from Textfile
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






