views:

65

answers:

2
+2  A: 

Use a base Geometry class:

class Geometry {
public:
    virtual ~Geometry() { }
    virtual void Render() = 0;
};

and have each of your Geometry-type classes derive from this base class and implement their specific rendering functionality by overriding Render.

Then, Renderer::RenderGeometry does not need to be a function template; it can simply take a pointer to the base Geometry class and call the virtual function Render.

James McNellis
Unfortunately, there are some troubles. Geometry should be independent from vertex type, which in my case is another template. I could probably solve this operating on some `variant`-type, but I thought there is a better workaround. *Anyway, thanks.*
HardCoder1986
@HardCoder1986: You can derive any number of types from the base `Geometry` class, so you could have a concrete class template derived from `Geometry` that also takes as a template argument the vertex type.
James McNellis
@James Thanks, I am stupid :) Looks like I had a hard day...
HardCoder1986
+1  A: 

Template is not neccessity. If you think hard about it, most of the time templates only do text-replacing and is a safer macros.

OOP was not design to rely heavily on templates, but composition and inheritance (like what James suggested)

kizzx2