对于我正在尝试编写的应用程序,我需要能够在interface编写GLEnable(GL_REPEAT)工作)。 一旦用户这样做,系统应该使用正确的参数调用该函数。
为此,我使用以下变量来获取正确的函数:
std::map<std::string, void(*)(GLenum)> glEnableDisable;
并通过以下方式存储数据:
glEnableDisable["glEnable"] = glEnable; glEnableDisable["glDisable"] = glDisable;(注意,上面给出警告“'='不能从'void(__ stdcall *)(GLenum)'转换为'void(__ cdecl *)(GLenum)'”)
最后,通过以下方式调用该函数:
((void (*)(GLenum)) Main.glEnableDisable[SplittedUp[0]])(Parameter);现在,我想知道我做错了什么。 我没有参数这个工作正常,但我真的需要参数。
提前致谢,
乔伊
For an application I'm trying to write I need to be able to write GLEnable(GL_REPEAT) in an interface (got this working). Once the user does that, the system should call the function with the correct parameter.
For this, I am using the following variable to get the correct function:
std::map<std::string, void(*)(GLenum)> glEnableDisable;
And storing data in it through:
glEnableDisable["glEnable"] = glEnable; glEnableDisable["glDisable"] = glDisable;(Note that the above gives a warning "'=' cannot convert from 'void (__stdcall *)(GLenum)' to 'void (__cdecl *)(GLenum)'")
Finally, the function is called through:
((void (*)(GLenum)) Main.glEnableDisable[SplittedUp[0]])(Parameter);Now, I wonder what I'm doing wrong. I had this working fine without parameters, but I really need parameters for this.
Thanks in advance,
Joey
最满意答案
改变这个:
std::map<std::string, void(*)(GLenum)> glEnableDisable;对此:
std::map<std::string, std::function<void(GLenum)>> glEnableDisable;并且再也不用担心召唤约定了。 std::function能够存储任何函数或可调用对象,无论其调用约定如何。
不需要演员:
Main.glEnableDisable[SplittedUp[0]])(Parameter);Change this:
std::map<std::string, void(*)(GLenum)> glEnableDisable;to this:
std::map<std::string, std::function<void(GLenum)>> glEnableDisable;and never worry about calling conventions again. An std::function is able to store any function or callable object, whatever its calling convention is.
Cast is not needed:
Main.glEnableDisable[SplittedUp[0]])(Parameter);更多推荐
发布评论