Several Patterns books will always say that composition is preferred over inheritance, because it makes your code more reusable, and more flexible. Let’s see a usual example of this in C++, using pointers or references:
class my_object {
private:
other_object * _p;
public:
explicit my_object (other_object * p) : _p(p) { };
void do_something() { [...]