Cannot Instantiate Immutable or Constant Structure Variable

Loopback elliott.darfink at gmail.com
Wed Jul 6 07:40:22 PDT 2011


On 2011-07-06 08:20, Jens Mueller wrote:
> Loopback wrote:
>> On 2011-07-06 04:39, Jose Armando Garcia wrote:
>>> First, you should always try to simplify the problem when asking for
>>> help. Not many people want to read a lot of code to find the issue.
>>
>> That's understandable indeed, though I haven't been able to distinguish
>> what's the exact property of the structure that is causing this error,
>> otherwise I would have gladly used a short sample.
>
> You may give DustMite a try. Maybe it can reduce it for you.
> https://github.com/CyberShadow/DustMite/wiki
>
> Jens

Thank you for the link! It was very useful.

I've stripped lots of code and now, it seems too simple to not be able
to figure out where the problem lies. I've always thought the error was
related to templates, but as I said; it was much more simple.

Perhaps the problem is obvious for those experienced in D but I am still
a rookie. I've also searched for a solution but I have found none.

struct DVector2
{
	float x, y;
	
	this(float x, float y)
	{
		this.x = x;
		this.y = y;
	}
}

void main(string[] args)
{
	// Creating This Vector Fails
	// 'Error: cannot evaluate __ctmp3.this(0F, 1F) at compile time'
	static immutable DVector2 _test = DVector2(0f, 1f);
	
	// Same with variable within class
	C c = new C;
}

class C
{
	// This code fails as well, with the same error
	immutable DVector2 _test = DVector2(0f, 1f);
}


More information about the Digitalmars-d mailing list