473,387 Members | 1,295 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Friendship inheritance

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
4 7510
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
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
"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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Erik | last post by:
private and protected members can only be accessed by deriving a class or by giving friendship. The problem with friendship is that friend statements are written inside the class. A FriendShip...
4
by: JH Trauntvein | last post by:
Consider the following example: namespace n1 { class cn1_base; namespace n1_helpers { class helper1 {
4
by: Mr Dyl | last post by:
I'm trying to declare the following friendship and VS.Net 2003 is complaining: template <class T> class Outter { class Inner {...} ... }
3
by: tom.s.smith | last post by:
I know that friendship isn't inherited in C++, and have two questions. (1) Why? Is it a technical problem, or just by design? If the latter, isn't this a little prescriptive, and shouldn't there...
2
by: Mark P | last post by:
Is there a way to do anything like the following: class A { friend void B::foo(); ... }; class B
4
by: werasm | last post by:
I've read the following somewhere: "Friendship is the strongest form of coupling there is. That is, you introduce a high degree of dependency when you declare a friend, since the friend becomes...
6
by: Hicham Mouline | last post by:
Hello, A semi-skeptical colleague is asking me why friendship is not inheritable, specifically: class Base { public: virtual void f() const =0; }; class Derived : public Base {
2
by: hanna88 | last post by:
hello... i am looking for a better way of doing Class Matrix. the current code i have now is Class Vector which is inherited from Class Base. Class Matrix needs the vector in Class Vector and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.