decltype 和静态模板方法

decltype and static template method

在尝试使用 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:

error: template argument 4 is invalid

对于 MSVC,一个出人意料的有用:

error C3553: decltype expects an expression not a type

我的目标是让编译器在表达式 GroupA::get<ObjectType>() 有效时选择专业化。

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

两个编译器实际上都没有给出有用的错误。真正的问题是您在 get:

之前缺少 template 关键字
template get<ObjectType>()

请参阅 Dependent Names

上的 cppreference 页面