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.

Recommended Answers

All 3 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.