首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MSVC:意外的标记'__cdecl',应为'expression‘

MSVC:意外的标记'__cdecl',应为'expression‘
EN

Stack Overflow用户
提问于 2018-07-05 17:09:08
回答 0查看 689关注 0票数 1

将一个应用程序移植到Windows上,我现在正在尝试用VS2017编译它,但遇到了一大堆问题。其中之一是,我编写的一个模板包装器( template wrapper )使C++成员函数可以从C库(FUSE)中调用,但它无法工作:

代码语言:javascript
复制
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)...);
    }
};

我试图在构造函数中像这样设置回调函数:

代码语言:javascript
复制
_operations.get_attr = Callback<std::remove_reference<decltype(*_high_level.getattr)>::type>::wrap<&operations::getattr>;

这是--我相信--有效的代码,但它不会包含一些警告和错误:

代码语言:javascript
复制
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。我不知道该怎么做。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51187424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档