import std.stdio;
class Hugo {
public int x = 42;
void blah(void function(Hugo h) f) {
f(this);
}
// OVERLOAD
void blah(void function(const Hugo h) f) const {
f(this);
}
}
void main() {
Hugo hugo = new Hugo();
void function(Hugo h) f = function(Hugo h) {
h.x = 99;
};
hugo.blah(f);
const Hugo inge = hugo;
// CHANGE TYPE HERE
void function(const Hugo h) g = function(const Hugo h) {
writeln("foobar");
};
inge.blah(g);
}
You need to overload on const, and also pass in a correctly typed
function as the argument (you can't call a function with a
mutable parameter with a const object.
- const Propagation Julian Kranz via Digitalmars-d
- Re: const Propagation Peter Alexander via Digitalmars-d
- Re: const Propagation Julian Kranz via Digitalmars-d
- Re: const Propagation Steven Schveighoffer via Digitalmars-d
- Re: const Propagat... Steven Schveighoffer via Digitalmars-d
- Re: const Pro... Julian Kranz via Digitalmars-d
