C++ Pointer member function with templates assignment with a member function of another class
- by Agusti
Hi, I have this class:
class IShaderParam{
public:
std::string name_value;
};
template<class TParam>
class TShaderParam:public IShaderParam{
public:
void (TShaderParam::*send_to_shader)( const TParam&,const std::string&);
TShaderParam():send_to_shader(NULL){}
TParam value;
void up_to_shader();
};
typedef TShaderParam<float> FloatShaderParam;
typedef TShaderParam<D3DXVECTOR3> Vec3ShaderParam;
In another class, I have a vector of IShaderParams* and functions that i want to send to "send_to_shader". I'm trying assign the reference of these functions like this:
Vec3ShaderParam *_param = new Vec3ShaderParam;
_param-send_to_shader = &TShader::setVector3;
This is the function:
void TShader::setVector3(const D3DXVECTOR3 &vec, const std::string &name){
//...
}
And this is the class with IshaderParams*:
class TShader{
std::vector params;
public:
Shader effect;
std::string technique_name;
TShader(std::string& afilename):effect(NULL){};
~TShader();
void setVector3(const D3DXVECTOR3 &vec, const std::string &name);
When I compile the project with Visual Studio C++ Express 2008 I recieve this error:
Error 2 error C2440: '=' :can't make the conversion 'void (__thiscall TShader::* )(const D3DXVECTOR3 &,const std::string &)' a 'void (__thiscall TShaderParam::* )(const TParam &,const std::string &)' c:\users\isagoras\documents\mcv\afoc\shader.cpp 127
Can I do the assignment? No? I don't know how :-S
Yes, I know that I can achieve the same objective with other techniques, but I want to know how can I do this..