Inheritance expresses aan is-ais-a relationship, while composition expresses a has-ahas-a relationship between the two classes.
An example for composition is a polygon. It has aan ordered sequence of Points. In C++ terms:
struct Polygon { std::vector<Point> points; }; struct Polygon { std::vector<Point> points; }; While an logic_error is a exception:
struct logic_error : public exception { }; struct logic_error : public exception { };