String::iterator::operator*() returns a const reference

Create issue
Issue #384 resolved
Former user created an issue

Automatic migration. Original reporter: "Timo"

CEGUI::String s("foo");

  • s.begin() = 98;

The above code gives a compiler error about assigning to a const variable (in MSVC2008). Took me some time to figure out what was going on because iterator::operator*() clearly returns "reference". But it doesn't actually mean String::reference, but std::iterator<>::reference, which is const, because its typedeffed from the template parameters given in String::const_iterator.

All the other types used in the iterator classes need to be checked too. I think at least "pointer" has the same issue.

branches/v0-7 r2600

Reproducibility: always

Comments (1)

  1. Paul Turner

    Should be fixed in branches/v0-7 r2635.

    The return types are correct and behave the same as std::string::iterator, which was one of the goals for CEGUI::String (and it's iterators).

    The issues here were actually due to String::iterator subclassing String::const_iterator, and so it was impossible to actually get an iterator that could work in a non-const manner.

  2. Log in to comment