【发布时间】:2014-10-01 08:12:05
【问题描述】:
我的代码需要像test 这样的函数。第 3 方希望它像 test2。使用下面的代码,我可以将函数 test 分配给 fn1 和 fn3rdParty 但我不知道如何使 fn1 与 fn3rdParty 一起使用
错误
错误 C2440: 'type cast' : 无法从 'std::function' 转换为 'void *(__cdecl *)(void *)'
代码
class Data {};
void*test(Data*data) { return 0; }
void*test2(void*data) { return 0; }
function<void*(Data*)> fn1 = test;
void*(*fn3rdParty)(void*) = test2;
fn3rdParty = (void*(*)(void*))test;
fn3rdParty = (void*(*)(void*))fn1;//error
【问题讨论】:
-
必须有更好的方法来做到这一点... ;)
标签: c++