【发布时间】:2016-02-15 18:13:55
【问题描述】:
我已经编写了 std::vector 的自定义子类:
template <class T>
class CustVec : public vector<vector<T>> {
public:
T& operator [](const pair<int, int> pos) {
return (*this)[pos.first][pos.second];
}
};
但是我遇到了错误No viable overloaded operator[] for type 'CustVec<pair<int, int>>'"。如何解决?
【问题讨论】:
-
你用什么编译器?
-
不要从标准容器继承。而是使用合成。
-
问题是
(*this)[pos.first]看起来像递归调用,但参数错误。 -
@Valentin,Xcode 7.1,但问题也出现在其他编译器上。