opCast and std.conv.to

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 22 05:15:30 PST 2015


On Sunday, 22 February 2015 at 13:04:56 UTC, Jacques Müller wrote:
> I tried to override the opCast operator in a class to be able 
> to explicitly convert the class to a string, but to!string just 
> returns the name of the class.

to!string actually forwards to a special function, "string 
toString() {}" which you'll need to implement and override from 
the base class.

It might need to be const too

override string toString() const { }

the compiler will tell you.


More information about the Digitalmars-d-learn mailing list