我尝试使用一组过滤器函数来运行基于字符串输入的适当例程。我尝试使用模板为常见情况创建matcher函数,但当我尝试存储指向专用函数的指针(在结构中,在实际应用程序中)时,会出现“type not equal to type”错误。
来自Visual C++ 8“控制台应用程序”的示例
template <const char *C>
const char*
f(void) {
return C;
}
const char* (*g)(void) = f<"hi">;
int _tmain(int argc, _TCHAR* argv[])
{
return g();
}
这个失败了
Error 1 error C2440: 'initializing' : cannot convert from 'const char *(__cdecl *)(void)' to 'const char *(__cdecl *)(void)' c:\files\pointer.cpp 7
(它在主返回值上也有一个错误,但这与我无关。)
如果
const char *
替换为int。