3 ms·
C++ gives you the freedom to choose between composition and subtyping to suit your problem without having to worry about an extra indirection if you choose comp
by detrino 13y ago
C++ gives you the freedom to choose between composition and subtyping to suit your problem without having to worry about an extra indirection if you choose composition.
For example, the base member of Composed is not a pointer as it might be in a language with reference semantics:
struct Base
{
int i;
};
struct Derived : Base
{
bool b;
};
struct Composed
{
Base base;
bool b;
};