c++ - How to compose a hierarchy of decorated classes without copying data -
i have 3 classes hierarchically related:
pattern, has protected field_panelsof typestd::vector<panel>.panel, in turn, has protected field_edges, of typestd::vector<edge>.edge, finally, has protected field_verts, of typestd::vector<eigen::vector2f>.
i have pure virtual class renderable, has pure virtual function virtual void render(). want create specialized versions of each of 3 classes inherit renderable, example:
class vpattern : public pattern, public renderable { public: void render() { ... } protected: ... private: ... }; // class vpattern however, _panels field still contain instances of panel, , not vpanel. mean have put drawing logic edge , panel in draw function of pattern, not ideal.
is there different approach here i'm not seeing avoid this? using wrapper class more suitable approach?
is there reason can't have drawable virtual class has pure virtual function draw() drawable descendents implement?
public virtual struct drawable { virtual void draw() = 0; }; public struct edge : drawable { void draw() {} }; //...
Comments
Post a Comment