Immutable member functions on mutable objects
Tomek Sowiñski
just at ask.me
Sun Nov 29 04:23:07 PST 2009
I've got a problem calling an immutable getter on an "ordinary" object.
struct A {
float _pole;
float pole() immutable {
return _pole;
}
}
void main() {
A a;
auto x = a.pole; // Ouch!
}
Error: function hello.A.pole () immutable is not callable using argument types ()
There's no problem when pole is const. I assume the problem is the hidden "this" parameter (is it? the message is a bit confusing). Then again, A is implicitly convertible to immutable(A) so there shouldn't be a problem, no? Maybe a compiler bug?
BTW, can someone explain what's exactly the difference between a const and immutable member function? The D page says only about the latter.
Tomek
More information about the Digitalmars-d-learn
mailing list