理解“模板参数无效”错误信息

4

Consider the code:

#include <type_traits>
#include <iostream>

struct test1 {
    void Invoke() {};
};

struct test2 {
    template<typename> void Invoke() {};
};


enum class InvokableKind {
    NOT_INVOKABLE,
    INVOKABLE_FUNCTION,
    INVOKABLE_FUNCTION_TEMPLATE
};

template<typename Functor, class Enable = void>
struct get_invokable_kind {
    const static InvokableKind value = InvokableKind::NOT_INVOKABLE;
};

template<typename Functor>
struct get_invokable_kind<
  Functor,
  decltype(Functor().Invoke())
  >
{
    const static InvokableKind value = InvokableKind::INVOKABLE_FUNCTION;
};

template<typename Functor>
struct get_invokable_kind<
  Functor,
  decltype(Functor().Invoke<void>())
  >
{
    const static InvokableKind value = InvokableKind::INVOKABLE_FUNCTION_TEMPLATE;
};


int main() {
    using namespace std;

    cout << (get_invokable_kind<test1>::value == InvokableKind::INVOKABLE_FUNCTION) << endl;
    cout << (get_invokable_kind<test2>::value == InvokableKind::INVOKABLE_FUNCTION_TEMPLATE) << endl;

}

我正在尝试创建一个测试"可调用性"具体定义的元函数。但是在GCC 4.5.3上,我遇到了编译错误:

prog.cpp:37:3: 错误: 模板参数2无效

这是什么意思?为什么我可以在decltype(Functor().Invoke())上进行特化,但不能在decltype(Functor().Invoke<void>())上进行特化?

1个回答

6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接