Le 18/06/2012 09:14, Mehrdad a écrit :
Okay, how about this? http://ideone.com/VMlzS
Does this break const?
import std.stdio;
class S
{
this(int a)
{
this.a = a;
this.increment = { this.a++; };
}
int a;
void delegate() increment;
void oops() const { this.increment(); }
}
void main()
{
auto c = new const(S)(0);
writeln(c.a);
c.oops();
writeln(c.a);
}
Depending on how it is specified, I think you should either :
- get an error when constructing c, because S isn't « constable ».
(delegate type cannot be consted, but can be unconsted safely).
- get an error when you try to call increment in oops, because the
delegate type can't ensure the constness of the operation.