I'm trying to find my ways in the C++ land and am increasingly confused by now. The toy application is a very basic OpenGL engine. So here's the (I guess simple) problem: I'd like to handle meshes of different vertex data, so I'd have e.g.
struct Vertex
{
Vector3f position;
}
struct VertexN : public Vertex
{
Vector3f normal;
}
Now I need a Mesh class, that holds the data and draws it. I've tried something like this:
template<class T>
class Mesh
{
public:
Mesh();
~Mesh();
void load(const T * vertices, int num);
void draw();
protected:
T * vertices_;
};
The different vertices have to be loaded and drawn differently and this can be done with template specialization.
My problem is that I like to have another class that holds instances of Mesh objects, but templated class members are obviously not allowed.
The other solution I can think of is to hold pointers to the base struct Vertex in Mesh, pass an identifier for the Vertex type used and then use switch statements in load() and draw() to allow for the different implementations.
What is the best way to accomplish this?
Any help is greatly appreciated.