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

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -