Use composition when you can and inheritance when you have to.
Use public inheritance if derived class can be used as-a base class. For example if it implements abstract interface or extends base class in some way.
There is also private/protected inheritance which is not often used. It is used if you need to inherit implementation but replace part of the implementation by your own functions (using virtual functions)