"multiple template parameter lists are not allowed" ?

"multiple template parameter lists are not allowed"?

本文关键字:not allowed are lists multiple template parameter      更新时间:2023-10-16

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

类:

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允许

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

您似乎想要存储指向Detour s的指针的vector。由于Detour的每个专门化都有不同(且不相关)的类型,因此不可能直接这样做。但是,如果您使Detour模板继承了某些IDetour接口,该接口提供了在Detour上操作所需的函数,那么您可以将AddDetour编写为:

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

and m_Detours as:

std::vector<IDetour *> m_Detours;