www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - writefln on interface array

reply strtr <strtr spam.com> writes:
Is it possible to have this output [null,"1"] in stead of Error: std.format
formatArg?

interface I{}
class C:I{
int index;
char[] toString(){ return toString(index) }
}

I[2] two_i;
I[1] = new C();
writefln(two_i);



Would be handy for debugging ;)
Apr 07 2010
next sibling parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 04/07/2010 06:13 AM, strtr wrote:
 Is it possible to have this output [null,"1"] in stead of Error: std.format
formatArg?

 interface I{}
 class C:I{
 int index;
 char[] toString(){ return toString(index) }
 }

 I[2] two_i;
 I[1] = new C();
 writefln(two_i);



 Would be handy for debugging ;)
s/interface I{}/interface I{ char[] toString(); }/ s/writefln(two_i)/writefln("%s",two_i)/ ? or see bug 535
Apr 07 2010
parent strtr <strtr spam.com> writes:
Ellery Newcomer Wrote:

 
 s/interface I{}/interface I{ char[] toString(); }/
 s/writefln(two_i)/writefln("%s",two_i)/
 
 ?
no :(
 
 or see bug 535
voted ++
Apr 07 2010
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 07 Apr 2010 07:13:07 -0400, strtr <strtr spam.com> wrote:

 Is it possible to have this output [null,"1"] in stead of Error:  
 std.format formatArg?

 interface I{}
 class C:I{
 int index;
 char[] toString(){ return toString(index) }
 }

 I[2] two_i;
 I[1] = new C();
 writefln(two_i);



 Would be handy for debugging ;)
Don't think this is exactly what you are looking for, but have you tried writeln? writefln requires the first argument to be a string, it didn't used to, but it was determined that the resulting behavior when you want to just print a string is too confusing. -Steve
Apr 08 2010