我创建了一个新类,它通过私有(private)继承组成 std::deque
,即,
class B : private std::deque<A>
{ ... };
在我的源代码中,我尝试使用 B 的迭代器,即,
B::iterator it
编译错误是
error C2247: 'std::deque<_Ty>::iterator' not accessible because 'B' uses 'private' to inherit from 'std::deque<_Ty>'
那么问题是,我怎样才能使迭代器可访问?
最佳答案
你必须提升这个迭代器类。
在公共(public)部分使用using关键字。
class B : private std::deque<A>
{ ...
public:
using std::deque<A>::iterator;
};
对于其他类型以及来自实现基类的其他函数也是如此。
关于c++ - 由于私有(private)继承而无法访问迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12533541/