出于一些必要的原因,我对一些标准容器进行了子类化,例如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
};
大多数时候,using
语法用于将这些方法带入子类的范围。
只有当我想做一些额外的事情时,显式重载才完成。
一切正常,除了std::vector::operator ==
没有进入范围并给出编译器错误:
错误:没有匹配
MyVector<int>::vector
{akastd::vector<int, std::allocator<int> >}::operator==
inMyVector<int>::vector {aka class std::vector<int, std::allocator<int>
我试图用自定义类来模拟这种情况,它编译得很好。
使用标准容器,编译失败。
通过浏览 的源代码std::vector
,我可以看到operator ==
类体内的存在。
将operator ==
纳入 范围的正确语法是MyVector
什么?