C++ 将标准容器成员方法带到其子类的范围;使用;语法不适用于运算符

C++ 将标准容器成员方法带到其子类的范围;使用;语法不适用于运算符,c++,inheritance,stl,using,C++,Inheritance,Stl,Using,出于一些必要的原因,我将一些标准容器(如std::vector)子类化为private继承 template<typename T> struct MyVector : private std::vector<T> { typedef std::vector<T> vector; using vector::begin; // ok using vector::end; // ok using vector::size; // ok

出于一些必要的原因,我将一些标准容器(如
std::vector
)子类化为
private
继承

template<typename T>
struct MyVector : private std::vector<T>
{
  typedef std::vector<T> vector;

  using vector::begin;  // ok
  using vector::end;  // ok
  using vector::size;  // ok
  using vector::operator ==;  // <---- error

  // Other customized methods
};
模板
struct MyVector:private std::vector
{
typedef std::向量;
使用vector::begin;//确定
使用vector::end;//确定
使用vector::size;//确定

使用vector::operator==;//标准容器中的大多数运算符重载都是非成员,因此您无法找到它们

不过,我会注意到这一点(根据我在标准中阅读的内容)不一定是这样。但是,大多数常见的实现似乎都可以做到这一点。如果您想使用
std::vector
操作符==
,您可以像标准中定义的那样重载它,使用您带来的东西,您可以这样做:

bool operator == (const MyVector &other) const
{
  const std::vector &this_ = *this, &other_ = other;
  return this_ == other_;
}

标准容器中的大多数运算符重载都是非成员,因此您无法找到它们

不过,我会注意到这一点(根据我在标准中阅读的内容)不一定是这样。但是,大多数常见的实现似乎都可以做到这一点。如果您想使用
std::vector
操作符==
,您可以像标准中定义的那样重载它,使用您带来的东西,您可以这样做:

bool operator == (const MyVector &other) const
{
  const std::vector &this_ = *this, &other_ = other;
  return this_ == other_;
}

operator==
不是非成员吗?根据它是。@JesseGood,你是对的。我通过eclipse浏览源代码,在我看来,
operator==
是它的一部分。除了重载
operator==
之外,还有别的方法吗?我认为重载
operator=
是正确的解决方案ion在这里。
操作符==
不是非成员吗?根据它是。@JesseGood,你是对的。我在eclipse上浏览源代码,它在我看来是
操作符==
的一部分。除了重载
操作符==
之外,还有其他方法吗?我认为重载
操作符==
是正确的这里是ect解决方案。