错误:无法将函数定义与现有声明匹配

error:unable to match function definition to an existing declaration

本文关键字:声明 定义 函数 错误      更新时间:2023-10-16

我遇到了问题,无法解决。当我编译时,我的所有函数都遇到了问题,我在这里举了一个例子。错误为 C2244:无法将函数定义与现有声明匹配。这是我的头文件。

template <typename T>
class Gestionnaire {
public:
    Gestionnaire();
    ~Gestionnaire();
    bool addElement(const T* element);
    bool removeElement(const T* element);
    template < typename P>
    bool removeContent(P& predicat);
    template < typename P>
    T* findElement(P& predicat) const;
    bool findElement(const T& element) const;
    private:
        std::list<T*> liste_;
};  
template<typename P>
template <typename T>
bool Gestionnaire<T>::removeContent(P& predicat) {
        std::remove_if(liste_begin(), liste_.end(), predicat);
}

您必须将template<typename P>template <typename T>切换为与声明中显示的顺序相同的顺序。模板参数的第一个列表用于类模板,第二个列表用于模板化成员函数:

template<typename T>
template<typename P>
bool Gestionnaire<T>::removeContent(P& predicat) {
        std::remove_if(liste_begin(), liste_.end(), predicat);
}