If you want the compiler to stop you from doing the wrong thing, one way to do this is:
class ShaderPTC { public: ShaderPTC( string filename, <other params> ); void Draw( VertexArray<VertexPTC>& Vertices ); ~ShaderPTC(); private: Shader m_shader; }
and
class ShaderPC { public: ShaderPC( string filename, <other params> ); void Draw( VertexArray<VertexPC>& Vertices ); ~ShaderPC(); private: Shader m_shader; }
You will make sure that the constructors create the corresponding shader inside themselves and pass the objects of this class with pointers / links, so you do not need to worry about copying the wrapped shader (you may want to make the constructors / copy assignment private as well).
Since the Draw function accepts only the correct type of vertex array, and the internal shader is not displayed, you cannot pass incorrect parameters.
If the code you have to write in the constructors and functions of Draw is generic, you can make it a template class. Otherwise, you will have to specialize the template in any case, so that the template approach does not have real benefits.
Although properly naming your variables can prevent such problems, properly typing variables will be much harder to break.
source share