A Wrapper
has a member of type Impl&
. Making the Wrapper
object const
only changes the top-level const
of its members (which does nothing on a reference, references are already non-rebindable), and even that takes effect only after the constructor finishes.
You need a class with a member of type const Impl&
, and const Wrapper
does not. The compiler is correctly preventing you from losing the const
qualifier and passing a const Impl&
to Wrapper::Wrapper(Impl&)
which could mutate its argument.
Generally const_iterator
is a separate class from iterator
. I see no reason why your Wrapper
would be any different.
As a short-term solution, you can just use
const Wrapper operator[](const std::string& mName) const { return global::getChild(impl, mName); }
but this doesn't prevent anyone from copying the return value into a non-const Wrapper
object and using it to mutate the Impl
.