By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,617 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,617 IT Pros & Developers. It's quick & easy.

Friendship inheritance

P: n/a
Is friendship inherited? Meaning if:

class Base {
public:
friend FriendClass;
};

class Derived : public Base {
}

Is FriendClass also a friend of Derived? Or does the friendship need to be
explicitly granted?

Thanks,
Martin
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Marcin Vorbrodt wrote:
Is friendship inherited? Meaning if:

class Base {
public:
friend FriendClass;
};

class Derived : public Base {
}

Is FriendClass also a friend of Derived?
No.
Or does the friendship need to be explicitly granted?


Yes.

--
Best regards,
Andrey Tarasevich
Brainbench C and C++ Programming MVP

Jul 19 '05 #2

P: n/a
Andrey Tarasevich wrote:
Marcin Vorbrodt wrote:

Is friendship inherited? Meaning if:

class Base {
public:
friend FriendClass;
};

class Derived : public Base {
}

Is FriendClass also a friend of Derived?

No.

Or does the friendship need to be explicitly granted?

Yes.


Just to add (because I think it's well expressed) -- take a look at:

http://www.parashift.com/c++-faq-lite/friends.html

BTW - reading through the entire FAQ would be a good idea -- and
remarkably entertaining, too!

HTH,
--ag

--
Artie Gold -- Austin, Texas

Jul 19 '05 #3

P: n/a
"Marcin Vorbrodt" <mv*****@eos.ncsu.edu> wrote in message news:<bj**********@uni00nw.unity.ncsu.edu>...
Is friendship inherited?


Friendship is not inherited, transitive, or reciprocal. Apparently,
enough people ask this that it's a FAQ:

<http://www.parashift.com/c++-faq-lite/friends.html>

While you're there, read the rest of the FAQs:

<http://www.parashift.com/c++-faq-lite/>

There is much knowledge to be had from those pages. :)

- Shane
Jul 19 '05 #4

P: n/a
> Is friendship inherited? Meaning if:

class Base {
public:
friend FriendClass;
};

class Derived : public Base {
}

Is FriendClass also a friend of Derived? Or does the friendship need to be
explicitly granted?


IMHO, you should take 5 minutes and try it with our favorite standard C++ compiler.
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.