Sturcts with constructor (dmd1.x)

Nrgyzer nrgyzer at googlemail.com
Mon Jan 11 14:06:13 PST 2010


Hello everyone,

I currently try to create a structure with a construtor, but I always get the following messages:

Error: Foo.this constructors are only for class definitions
Error: constructor lisim.lsResult.lsResult.this special member functions not allowed for structs

By compiling the follwing code:

struct Foo {
    int len;
    bool len_done;
    const char* str;
    int length()
    {   if (!len_done)
        {   len = strlen(str);
	    len_done = true;
        }
	return len;
    }
    this(char* str) { this.str = str; }
}
const Foo f = Foo("hello");
bar(f.length);

I found that source on http://www.digitalmars.com/d/2.0/const-faq.html#logical-const. I know that this source is for d2 and not for d1 but does d1 support similar operations (or is there no support for struct-constructors)?

Thanks in advance :)



More information about the Digitalmars-d mailing list