我有一个自定义结构SortedArrayList<T>,根据比较器对其元素进行排序,我想阻止使用operator[].
例:
ArrayList.h
template <typename T> class ArrayList : public List<T> {
virtual T& operator[](const int& index) override; //override List<T>
virtual const T operator[](const int& index) const override; //override List<T>
}
Run Code Online (Sandbox Code Playgroud)
SortedLinkedList.h包含以下运算符
template <typename T> class SortedArrayList : public ArrayList<T> {
public:
SortedArrayList<T>(const std::function<bool(const T&, const T&)>& comparator);
T& operator[](const int& index) override; //get reference (LHS)
const T operator[](const int& index) const override; //get copy (RHS)
}
Run Code Online (Sandbox Code Playgroud)
Test.h
ArrayList<int>* regular = new ArrayList<int>();
ArrayList<int>* sorted = …Run Code Online (Sandbox Code Playgroud)