c++ - How to compose a hierarchy of decorated classes without copying data -


i have 3 classes hierarchically related:

  • pattern, has protected field _panels of type std::vector<panel>.
  • panel, in turn, has protected field _edges, of type std::vector<edge>.
  • edge, finally, has protected field _verts, of type std::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

Popular posts from this blog

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -

SQL Server - MyCTE query based on 24 hour period (next day) -