从 className * 到 className & 的转换问题(反之亦然)

Problem with conversion from className * to className &(and the reverse)

看在上帝的份上,有人可以帮助我吗?我已经坚持了几个小时 这是“父亲”.h 文件,我不允许完全改变


//------------ Declarations for List traits used in Test1 in main.cpp

template <typename T>
class ListTraits
{
public:
    virtual unsigned int size() = 0;
    virtual ListTraits& insert(const T& item) = 0;
    virtual void print() = 0;
};

//------------ Declarations for List traits used in Test2 in main.cpp
template <typename T>
class ListTraitsExtended
{
public:
    virtual const T* getCurrentElement() const = 0;
    virtual void advance() = 0;
    virtual void rewind() = 0;
};

这是“子”.h 文件,

#include "ListTraits.h"
#include <array>


template <typename T>
class List : public ListTraits<T>
{
protected:

    std::array<int, 7> data;

public:
    
    unsigned int size() override{
        return 0;
    }
    void print() override {

    }
    List & insert(const T& item) override {
        return this;
        
    }
};

我总是遇到这个错误:

'return' 无法从 List * 转换为 List &

如果我这样做

return *这个;

我仍然遇到错误...

我到底做错了什么?我无法理解它

List& List::insert(const T &item) 声明为 return 对 List 的引用。 this 是指向 List 的指针。要 return 对列表的引用,return *this:

List & insert(const T& item) override {
    return *this;
}