Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Friendship and nested classes

Reply
Thread Tools

Friendship and nested classes

 
 
Juha Nieminen
Guest
Posts: n/a
 
      06-13-2008
Assume we have this kind of class hierarchy:

class A
{
class B;
};

class C
{
friend A;
};

Can B access the privates of C? What are the rules of friendship scope?
 
Reply With Quote
 
 
 
 
Saeed Amrollahi
Guest
Posts: n/a
 
      06-13-2008
On Jun 13, 12:44*pm, Juha Nieminen <(E-Mail Removed)> wrote:
> * Assume we have this kind of class hierarchy:
>
> class A
> {
> * * class B;
>
> };
>
> class C
> {
> * * friend A;
>
> };
>
> * Can B access the privates of C? What are the rules of friendship scope?


I think the best practice is try the code in a typical C++
environment. Also see the following link:
http://parashift.com/c++-faq-lite/friends.html

Regards,
Saeed Amrollahi
 
Reply With Quote
 
 
 
 
Martin York
Guest
Posts: n/a
 
      06-13-2008
On Jun 13, 2:44*am, Juha Nieminen <(E-Mail Removed)> wrote:
> * Assume we have this kind of class hierarchy:
>
> class A
> {
> * * class B;
>
> };
>
> class C
> {
> * * friend A;
>
> };
>
> * Can B access the privates of C? What are the rules of friendship scope?


No.

Just because you are my friend: (And I let you drive my car)

* I don't necessarily trust your kids. (Especially with my car)
* I don't necessarily trust your friends.(Especially with my car)
* You don't need to trust me. (With your Ferrari)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does friendship extend to inner classes? Juha Nieminen C++ 9 06-13-2011 04:46 PM
friendship with nested class Mr Dyl C++ 4 11-25-2005 05:16 PM
Nested Vector Nester Classes are Nested in my Brain Chad E. Dollins C++ 3 11-08-2005 04:46 AM
Nested Classes vs Top-Level Classes kelvSYC Java 2 08-18-2004 07:09 AM
What is the difference between nested classes and inner classes ? Razvan Java 5 07-27-2004 07:59 PM



Advertisments