我的列表类正在使用operator []。我可以使用这个重写类。如果有任何理由不提供运营商[]的名单,请解释。如果在下面的代码中有任何错误,请清除它。operator [] list cpp
template<class _Ty,class _Ax = std::allocator<_Ty>> class listadv : public
std::list<_Ty,_Ax>
{
// should declare in top of the class
public:
_Ty operator[](int index)
{
std::list<_Ty,_Ax>::iterator iter = this->begin();
std::advance(iter, index);
return *iter;
}
};
定义在标头类中。
从一个标准集装箱公有继承从来都不是一件好事。 –