Handle FormatSpec!char in the virtual toString() method of a class.

realhet real_het at hotmail.com
Wed May 13 12:26:21 UTC 2020


Hello,

Is there a way to the following thing in a class instead of a 
struct?

--------------------------------------
static struct Point
{
     int x, y;

     void toString(W)(ref W writer, scope const ref 
FormatSpec!char f)
     if (isOutputRange!(W, char))
     {
         // std.range.primitives.put
         put(writer, "(");
         formatValue(writer, x, f);
         put(writer, ",");
         formatValue(writer, y, f);
         put(writer, ")");
     }
}
--------------------------------------

I think the problem is that the toString() in a class is virtual, 
and don't let me to have multiple overloaded methods.

Is there a way to let format() deal with classes too?

Thank You!


More information about the Digitalmars-d-learn mailing list