which better?

/// Lets say that I have a class "myClass" that containes a lot of funtions
1
2
3
4
5
6
class myClass
{
    /*
        Functions
    */
};


so I want to use these functions in "mySecondClass" but I dont know what to choose between these two manners
should I inherit them like this

1
2
3
class mySecondClass:public myClass
{
};


or declare a pointr of myClass ,and access them through this pointer

1
2
3
4
class mySecondClass
{
    myClass *mc;
}


thanks for reading
Last edited on
They're for different purposes, so it depends on what you're trying to do.

For example, I have an arm I can use to grab things. However, I'm not a kind of arm; there are things arms can do I can't, such as being part of someone else's body. This is composition.

On the other hand, I am a hominid. Like all hominids, I can move about and grab things with my hands. If you wanted to have list of hominids so that you could tell all of them to move towards a table and grab a banana, I could be part of that list. A dog couldn't. This is inheritance.
Thanks Helios

Still opened for more info
Topic archived. No new replies allowed.