What is the difference between friendship and inheritance?

Seriously, what's the difference between

1
2
3
4
5
6
7
8
9
class A
{
    A()
    {
    }
    friend class B;
    friend class C;
};


and

1
2
3
4
5
6
7
8
9
10
11
12
class A
{
    A()
    {
    }
};
class B:public A
{
};
class C:public A
{
};
¿what's the difference between broken glass and a hamburger?
Be careful next time you eat something.
¿what's the difference between broken glass and a hamburger?
Be careful next time you eat something.


You're not being helpful here.
it allows class B and class C to do whatever they want with class a ,and even directly access their data members. inheritance is used for Cold reusability for hierarchies and promotes encapsulation. Friend classes on the other hand usually break encapsulation.
Last edited on
The concepts are too far apart that I don't understand why you are confusing them.

The concepts are too far apart that I don't understand why you are confusing them.


I'm still a beginner so please go soft on me.

What's the difference other than the fact that friends can also be included for functions while inheritance can't, polymorphism and also what GKneeus said.

Are there any differences other than that ?
Last edited on
What's the difference other than the fact that friends

The real question is what's the commonality? There isn't any. They accomplish different things by different methods and are used for different reasons.

Thus the confusion. It would seem you haven't researched them to any degree if you're looking for "differences." That's all there are.
Topic archived. No new replies allowed.