Constant iterator for a Binary Search Tree

Hi everyone,

I'm implementing a Binary Search Tree and I need to write my own iterator in order to move from a Node to another. I need to implement also a constant version of the iterator.

For instance, I need to implement a member function begin that returns an iterator to the leftmost node of the tree.

In particular, it's written in the notes from my teacher to implement the following functions:

1
2
3
iterator begin();
const_iterator begin() const;
const_iterator cbegin() const;


I can't see what is supposed to be the difference between const_iterator begin() const; and const_iterator cbegin() const;
Last edited on
https://stackoverflow.com/questions/31208640/what-is-the-difference-between-cbegin-and-begin-for-vector

The difference between begin() and cbegin() for your custom class container is the same as for a std::vector.
Thanks @FerryGuy. So it's just just for readability.

So, the third function must be called when we know a-priori that the object is const-qualified, while the second one is just an overloading of the original iterator begin(); so that I can call begin both on const and non-const-qualified objects
Topic archived. No new replies allowed.