【问题标题】:decltype and static template methoddecltype 和静态模板方法
【发布时间】:2016-05-09 09:49:49
【问题描述】:

在尝试使用 SFINAE 时,以下代码编译失败:

template<typename ObjectType, typename GroupA, typename GroupB, typename = void>
struct DelegateImpl; // default version

template<typename ObjectType, typename GroupA, typename GroupB>
struct DelegateImpl<ObjectType, GroupA, GroupB, decltype(GroupA::get<ObjectType>())>; // specialization

使用 GCC:

错误:模板参数 4 无效

使用 MSVC,一个惊人的帮助:

错误 C3553:decltype 需要一个表达式而不是类型

如果表达式 GroupA::get&lt;ObjectType&gt;() 有效,我的目标是让编译器选择特化。

问题:如何将 decltype 与静态模板方法一起使用?

【问题讨论】:

标签: c++ c++11 sfinae


【解决方案1】:

实际上这两个编译器都没有给出有用的错误。真正的问题是您在get 之前缺少template 关键字:

template get<ObjectType>()

参见Dependent Namescppreference 的页面

【讨论】:

    猜你喜欢
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 2011-10-20
    • 1970-01-01
    • 2019-06-21
    • 1970-01-01
    相关资源
    最近更新 更多