gpt4 book ai didi

c++ void *到函数的参数

转载 作者:太空狗 更新时间:2023-10-29 23:37:14 26 4
gpt4 key购买 nike

我在一些图书馆有这个功能:

class myConsole
{
void addCommand( std::string command, void* fn );
...
}

在我的课上我有这个功能:

void myApp::TestFn( const std::vector<std::string> & args )
{
// do something
}

在同一个类中我称之为:

void myApp::initApp( )
{
myConsole::getSingleton( ).addCommand( "FirstTest", &myApp::TestFn );
}

但这给了我这个错误:

error c2664 cannot convert parameter 2 from 'void(__thiscall myApp::*)(const std::vector<_Ty>&)' to 'void *'

我该如何解决这个问题?

提前致谢!

最佳答案

You can't解决这个。您无法可靠地将函数指针转换为 void * 并返回。

(我建议您重新设计程序并远离 void*;在 C++ 中没有真正需要它。)

关于c++ void *到函数的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8743959/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com