这是一个后续问题的答案,以是否有可能的typedef指针到extern-"C" -函数模板中的类型?
此代码无法使用g++Visual C/C++和Comeau C/C++进行编译,并且具有基本相同的错误消息:
#include <cstdlib>
extern "C" {
static int do_stuff(int) {
return 3;
}
template <typename return_t_, typename arg1_t_>
struct test {
static void foo(return_t_ (*)(arg1_t_)) { }
};
}
int main()
{
test<int, int>::foo(&do_stuff);
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
g ++说"错误:带C链接的模板",Visual C/C++发出编译器错误C2894,而Comeau C/C++说"错误:此声明可能没有extern"C"链接".
问题是,所有人都满意:
#include <cstdlib>
extern "C" {
static int do_stuff(int) {
return 3;
}
struct test {
static void foo(int (*)(int)) { }
};
}
int main()
{
test::foo(&do_stuff); …Run Code Online (Sandbox Code Playgroud)