【问题标题】:"multiple template parameter lists are not allowed"?“不允许使用多个模板参数列表”?
【发布时间】:2014-05-14 04:09:05
【问题描述】:

我正在编写一个简单的类来管理一些代码弯路。

班级:

class CDetourManager {
public:

    CDetourManager() {}

    ~CDetourManager() {}

    template<convention_type tp, typename retn, typename ...args>
    VOID AddDetour( Detour<tp, retn, args...>* d ) {
        m_Detours.push_back( d );
    }

private:
    template<convention_type tp, typename retn, typename ...args>
    std::vector<Detour<tp, retn, args...>* > m_Detours;
};

但我得到一个错误:
Error 1 error C3857: 'CDetourManager::m_Detours': multiple template parameter lists are not allowed

有谁知道我可以做些什么来摆脱这个错误?这是我第一次使用模板,所以我有点迷失在这里:(

【问题讨论】:

  • 那不行,m_Detours 没有明确的类型。

标签: c++ templates


【解决方案1】:

您似乎想存储指向Detours 的指针vector。由于Detour 的每个特化都有不同的(且不相关的)类型,因此这是不可能直接实现的。但是,如果您让Detour 模板继承自一些IDetour 接口,该接口提供了操作Detour 所需的功能,那么您可以将AddDetour 编写为:

void AddDetour(IDetour *d) {
    m_Detours.push_back(d);
}

m_Detours 为:

std::vector<IDetour *> m_Detours;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-27
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    相关资源
    最近更新 更多