更新时间:2022-11-22 20:02:36
你的 IList
是一个抽象类,有六个纯虚成员函数.为了创建派生实例(即LinkedList
),您需要也在孩子内部实现这些功能.
Your IList
is an abstract class with six pure virtual member functions. In order to create the instance of the derived one (i.e. LinkedList
) you need to implement those functions inside the child as well.
class LinkedList : public IList
{
// ..... other members
public:
// ..... other members
virtual int getCurrentSize() const override;
bool isEmpty() const override { // implementation }
bool add(int newEntry) override {// implementation }
bool remove(int anEntry) override { // implementation }
bool contains(int anEntry) override { // implementation }
void clear() override { // implementation}
};
还建议使用 override
说明符覆盖基类中的虚函数,以便编译器和读者都可以轻松识别它们,而无需查看基类.
Also recommended using the override
specifier to override the virtual functions from the base class, so that both the compiler and the reader can easily recognize them, without looking into to the base.
其他问题:
LinkedList
)中的 getCurrentSize()
函数声明缺少 const
.cout 中的错字数据 >>"";
应该是 cout
getCurrentSize()
functions declaration in the child class (i.e. LinkedList
) lacks a const
.cout << p -> data >> " ";
should be cout << p->data << " ";