What is the difference between friendship and inheritance?

Jun 21, 2014 at 9:57am
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
{
};
Jun 21, 2014 at 10:41am
¿what's the difference between broken glass and a hamburger?
Be careful next time you eat something.
Jun 21, 2014 at 10:56am
¿what's the difference between broken glass and a hamburger?
Be careful next time you eat something.


You're not being helpful here.
Jun 21, 2014 at 11:22am
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 Jun 21, 2014 at 11:24am
Jun 21, 2014 at 1:03pm
The concepts are too far apart that I don't understand why you are confusing them.
Jun 21, 2014 at 2:03pm

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 Jun 21, 2014 at 2:04pm
Jun 21, 2014 at 6:28pm
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.