0

Hi, I am trying to construct a binary tree using a list.

class Element
{
private:
    list<Element*> _children;
    char* _name;
    //...other data members and methods
}

I have a class ("Element") that has children ("_children"), but I cannot figure out how to add children to the elements of "_children".

I can only use the "const_iterator" because when calling "_children.begin()" returns a const_iterator.

Can someone tell me how I can modify the values in a list?

Thank you.

4
Contributors
3
Replies
10
Views
2 Years
Discussion Span
Last Post by David W
0

Are you using begin() or cbegin()? begin() should be a bidirectional iterator. Basically assign it to an iterator instead of a const_iterator and you can change its value.

0

Also, symbols that start with an underscore, such as _children, are reserved. Use something like m_children, indication a member variable, or s_children for a static variable.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.