I am trying to find my way in C ++ land and am getting more and more confused. The toy application is a very simple OpenGL engine. So here is a (I think simple) problem: I would like to process grids of different vertex data, so I would have, for example,
struct Vertex { Vector3f position; } struct VertexN : public Vertex { Vector3f normal; }
Now I need a Mesh class that stores data and draws it. I tried something like this:
template<class T> class Mesh { public: Mesh(); ~Mesh(); void load(const T * vertices, int num); void draw(); protected: T * vertices_;
};
Different vertices need to be loaded and drawn in different ways, and this can be done using specialized specialization.
My problem is that I like to have another class that contains instances of Mesh objects, but the template members of the class are obviously not allowed.
Another solution I can come up with is to hold pointers to the Vertex base structure in Mesh, pass the identifier for the Vertex type used, and then use the switch statements in load () and draw () to allow various implementations.
What is the best way to do this?
Any help is greatly appreciated.
bbtrb source share