Why D const is annoying
Jonathan M Davis
jmdavisProg at gmx.com
Wed May 2 13:02:17 PDT 2012
On Wednesday, May 02, 2012 11:58:41 Mehrdad wrote:
> Er, I guess I didn't say what I actually meant to say, my bad. x_x
>
> What I meant that you're assuming that derived classes won't need mutable
> state in an const method that they overrode.
If a const function needs mutable member variables or non-const member
functions, then it cannot exist. And so if a derived class requires that, then
it cannot exist. Putting const on a member function puts certain requirements
on it (the same goes for nothrow, pure, and @safe), and any derived class must
meet those requirements with its overridden version. It's part of the function's
signature just like the return type is.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list