www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Struct constructors

reply Sean Eskapp <eatingstaples gmail.com> writes:
In code like this:

import std.stdio;

struct foo
{
	int val;

	static immutable bar = foo(1);

	this(int val)
	{
		this.val = 50;
	}
}

void main()
{
	writeln(foo.bar.val);
}

The user-defined struct constructor is not called, because it's overridden by
a built-in constructor which treats it like an initializer list. Shouldn't
constructors in structs either generate errors/warnings, or work as they would
appear to?
Jan 20 2011
next sibling parent =?UTF-8?B?U8O2bmtlIEx1ZHdpZw==?= <ludwig informatik.uni-luebeck.de> writes:
Am 20.01.2011 19:42, schrieb Sean Eskapp:
 In code like this:

 import std.stdio;

 struct foo
 {
 	int val;

 	static immutable bar = foo(1);

 	this(int val)
 	{
 		this.val = 50;
 	}
 }

 void main()
 {
 	writeln(foo.bar.val);
 }

 The user-defined struct constructor is not called, because it's overridden by
 a built-in constructor which treats it like an initializer list. Shouldn't
 constructors in structs either generate errors/warnings, or work as they would
 appear to?

See http://d.puremagic.com/issues/show_bug.cgi?id=3863.
Jan 20 2011
prev sibling parent reply Trass3r <un known.com> writes:
Probably related to http://d.puremagic.com/issues/show_bug.cgi?id=5460
Jan 20 2011
parent Sean Eskapp <eatingstaples gmail.com> writes:
That looks like a similar issue. Thanks!
Jan 20 2011