【问题标题】:C++ error in template function call: type name is not allowed模板函数调用中的 C++ 错误:不允许类型名称
【发布时间】:2017-07-15 16:17:54
【问题描述】:

Diab 编译器在@@@ 行中抱怨不允许类型名称。

template<
    Task TASK,
    Event EVENT>
class TManager :
    public AbstractTManager,
    public common::ITManager
{
    public:
    typedef os::EManager<TASK>  tEManager;

    TManager()
    { /* ... */}

    virtual void init()
    {

        tEManager::registerCallback<
            EVENT,
            TManager, /* @@@ */
            &TManager::func>(*this);
    }

    void func()
    { /* ... */}
}

EManager 中的 registerCallback 定义如下:

template<TType task>
class EManager
{
public:
    template<
        EType event,
        typename e_listener,
        void (e_listener::*TMethod)()
        >
    static void registerCallback(e_listener& listener)
    {
        /* ... */
    }
}

第二个模板参数是带有关键字 typename 的 e_listener,所以我不知道为什么它会报告问题。我错过了什么? 提前感谢您的帮助。

【问题讨论】:

标签: c++ c++11 templates


【解决方案1】:

你应该添加template:

tEManager::template registerCallback<
        EVENT,
        TManager,
        &TManager::func>(*this);

【讨论】:

    【解决方案2】:

    谢谢 Jarod42 和克里斯。有用!我错过了这个非常有价值的主题,其中包括“模板关键字”一章中的解决方案: Where and why do I have to put the "template" and "typename" keywords?

    【讨论】:

      猜你喜欢
      • 2015-10-08
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 2011-11-04
      相关资源
      最近更新 更多