How to turn an inout(Object) into a string
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Apr 25 22:09:30 PDT 2015
On Sunday, 26 April 2015 at 04:52:36 UTC, Jonathan M Davis wrote:
> It's only undefined if mutation is involved, though I don't
> know if mutation is involved in this case or not
I was thinking that a class can define an arbitrary toString()
that modifies it some of its member variables, which definitely
breaks const-correctness.
class CustomToString
{
int n;
override string toString()
{
n = 1;
return "Uh oh";
}
}
void main()
{
import std.stdio;
immutable c = new CustomToString();
writeln(cast()c);
}
More information about the Digitalmars-d-learn
mailing list