Type.stringof

Michiel nomail at please.com
Thu Feb 22 03:15:25 PST 2007


Walter Bright wrote:

>> The documentation sais that all types should have the property
>> .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
>> it exist (anymore)?
> 
> In what case does it not work?

Any case. I tried this:

------------------------------------------
module test;

import std.stdio;

struct Foo { }

enum Enum { RED }

typedef int myint;

void main()
{
    writefln((1+2).stringof);       // "1 + 2"
    writefln(Foo.stringof);         // "Foo"
    writefln(test.Foo.stringof);    // "test.Foo"
    writefln(int.stringof);         // "int"
    writefln((int*[5][]).stringof); // "int*[5][]"
    writefln(Enum.RED.stringof);    // "Enum.RED"
    writefln(test.myint.stringof);  // "test.myint"
    writefln((5).stringof);         // "5"
}
------------------------------------------

And got these errors:

------------------------------------------
main.d(13): Error: no property 'stringof' for type 'int'
main.d(14): Error: no property 'stringof' for type 'Foo'
main.d(15): Error: no property 'stringof' for type 'Foo'
main.d(16): Error: no property 'stringof' for type 'int'
main.d(17): Error: no property 'stringof' for type 'int*[5][]'
main.d(18): Error: no property 'stringof' for type 'int'
main.d(19): Error: no property 'stringof' for type 'int'
main.d(20): Error: no property 'stringof' for type 'int'
------------------------------------------


-- 
Michiel



More information about the Digitalmars-d mailing list