[lug] OT: C++ question, const_iterator design

Tkil tkil at scrye.com
Sun Jun 1 02:39:07 MDT 2003


>>>>> "DS" == D Stimits <stimits at attbi.com> writes:

DS> When I do this it works:

DS>    iterator it_non_const = foo.begin();

DS> When I do this, it fails:

DS>    const_iterator it_const = foo.begin();

How about:

   const_iterator it_const = const_cast<const MyContainer>(foo).begin();

This is based on the idea that, unless foo is declared to be const,
then foo.begin is resolved to a call to the plain begin() (not
"begin() const").

If that doesn't work, a copy of the actual diagnostic message would be
helpful.

t.





More information about the LUG mailing list