且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

复制和分配构造函数的问题

更新时间:2022-12-13 22:16:59

根据错误消息,您的 LinkedList 似乎没有 begin() end()可以在const对象上调用。但是,复制构造函数和赋值运算符的参数是const。您必须添加 begin() end()的const版本。

Based on the error message, it would seem that your LinkedList does not have variants of begin() and end() that can be called on a const object. The parameters to your copy constructor and assignment operator are const, however. You will have to add const versions of begin() and end().

想必您正在寻找这样的东西:

Presumably, you're looking for something like this:

    ConstIterator begin() const { Iterator(sp_Head); }
    Iterator begin() { Iterator(sp_Head); }

    ConstIterator end() const { ConstIterator(nullptr); }
    Iterator end() { Iterator(nullptr); }

其中 ConstIterator 是您的版本迭代const元素的迭代器类型…

Where ConstIterator is a version of your iterator type that iterates over const elements…