当使用可变参数模板保存函数的地址时,g ++编译器(版本4.8.2)输出以下错误:
没有上下文类型信息的重载函数的地址
有问题的代码:
template<typename... Args>
void redirect_function(const char *format, Args... args)
{
pLog->Write(format, args...); // or: printf(format, args...);
}
void *fnPtr = (void *)&redirect_function; // The error occurs here.
这是我在其他地方使用的方法:
typedef void (*log_bridge)(const char*, ...);
log_bridge LogWrite;
LogWrite = (log_bridge)fnPtr;
我对此没有其他可能性,所以请不要提出完全不同的解决方法。
好吧。很简单为什么不行。你有明显的模棱两可。redirect_function
不是函数;作为所有模板函数,它更像是模板针对不同类型的参数生成的一组重载。
该函数需要首先实例化才能获得其地址,并且您没有为此提供任何必要的信息。
换句话说,问题是您可能无法知道redirect_function
问题线路上应使用哪个具体的重载。
您唯一可以做的就是显式提供模板参数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句