我希望在向量上定义一个迭代器类,它的私有成员如何p
匹配 std::vector::begin() 的返回类型?
class A{
struct element{
...
}
class e_iterator {
e_iterator() : p()
...
private:
element* p;
};
e_iterator e_begin() const{
e_iterator Iter;
Iter.p = e_.begin(); // error
return Iter;
}
std::vector<element> e_;
我收到一个错误element* p
:
error: cannot convert 'std::vector<element, std::allocator<element>>::const_iterator' to 'element*' in assignment