将一个应用程序移植到Windows上,我现在正在尝试用VS2017编译它,但遇到了一大堆问题。其中之一是,我编写的一个模板包装器( template wrapper )使C++成员函数可以从C库(FUSE)中调用,但它无法工作:
template <class T> class Callback {};
template <class T, class ...Arguments>
struct Callback<T(Arguments...)>
{
template <T(operations::*CALLBACK)(Arguments...)>
static T wrap(Arguments... parameters)
{
auto *instance = static_cast<operations*>(fuse_get_context()->private_data);
return (instance->*CALLBACK)(std::forward<Arguments>(parameters)...);
}
};我试图在构造函数中像这样设置回调函数:
_operations.get_attr = Callback<std::remove_reference<decltype(*_high_level.getattr)>::type>::wrap<&operations::getattr>;这是--我相信--有效的代码,但它不会包含一些警告和错误:
warning C4229: anachronism used: modifiers on data are ignored
error C2760: syntax error: unexpected token '__cdecl', expected 'expression'
note: see reference to function template instantiation 'T Callback<int (const char *,stat64_cygwin *)>::wrap<int operations::getattr(const char *,stat64_cygwin *)>(const char *,stat64_cygwin *)' being compiled
with
[
T=int
]
note: see reference to function template instantiation 'T Callback<int (const char *,stat64_cygwin *)>::wrap<int operations::getattr(const char *,stat64_cygwin *)>(const char *,stat64_cygwin *)' being compiled
with
[
T=int
]
error C2059: syntax error: '__cdecl'有关计时错误的警告指向包含wrap函数的模板规范的行。错误指向在wrap函数内实际调用和返回回调的那一行。
这非常令人困惑,在读了一些东西之后,我发现时代错误是Windows中使用的那种属性,我在这里没有用到它,而且我在这里也没有任何__cdecl。我不知道该怎么做。
https://stackoverflow.com/questions/51187424
复制相似问题