c++ - Multiple inheritance and generic program -
i reading "modern c++ design: generic programming , design patterns applied" andrei alex., started. @ page 6, has following critcism of multiple inheritance:
the problems assembling separate features using multiple inheritance follows:
- ...
- type information. base classes not have enough type information carry out tasks. example, imagine try implement deep copy smart pointer class deriving
deepcopy
base class. interfacedeepcopy
have? must create objects of type doesn't know yet.
i wondering if particular critique flawed.
interface driven design has base class pure virtual class , child class implements interfaces. take deepcopy example, this:
struct deepcopy { virtual void copy(deepcopy *src) = 0; }; class myclass : public deepcopy, public anotherintf { public: virtual void copy(deepcopy *src); };
in example, myclass implementer , real class.
maybe miss point of andrei's critique here.
what think?
it understanding alexandrescu speaking of external copying facility here, not intrusive 1 requires modification of classes being copied. proper way implement deep copy given class may differ based on class's implementation, without way provide type information external copying facility can't select proper approach.
deep copy may not great example here -- chapters on generalized functors, smart pointers, , multiple dispatch consider better real-world examples of policy-based design.
Comments
Post a Comment