C++ Composition? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

C++ Composition?

I'm stuck trying to understand composition in c++. I don't want to move on until I understand it. Can somebody give me a good explanation or link me a tutorial for this? It'd be greatly appreciated.

12th Nov 2018, 9:28 PM
Daniel Cooper
Daniel Cooper - avatar
5 Answers
12th Nov 2018, 10:20 PM
Izaak GOLDSTEIN
Izaak GOLDSTEIN - avatar
+ 4
To the best of my memory, it's about having an object of class A as a member of class B. If class B inherits from class A, we say that class B is-a class A. E.g. A fish is an animal. The fish has traits of an animal. If class B contains an object of class A (composition), we say that class B has-a class A. E.g. A kid has a ball. class Ball { int radius, diameter; // etc }; class Kid { Ball myBall; // etc };
13th Nov 2018, 3:48 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
12th Nov 2018, 10:34 PM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Maybe little help you
12th Nov 2018, 10:57 PM
Izaak GOLDSTEIN
Izaak GOLDSTEIN - avatar
+ 1
I know it as function composition. If you have two functions `f(x)` and `g(x)`, then a function returning `f(g(x))` is called the composition of `f` and `g`.
13th Nov 2018, 5:17 AM
Schindlabua
Schindlabua - avatar