I don't get it. version(unittest) can't seem to use local variable

dysmondad via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 11 22:08:18 PDT 2014


I'm new to D. I've been using C since it was a baby and C++ back 
when it was only a pre-compiler for c. So, I may just be stuck 
thinking in C land.

The issue is I am attempting to use the version(unittest) 
feature. However the compiler pukes up the error below. I'm sure 
it's something easy enough but I've not been able to find any 
help in Google land. I don't know if I have the opOpAssign 
defined correctly or if there's something wrong with the 
constructor or both.

dysmondad at Julep:~/src/D$ gdc -c velocity.d
velocity.d:110: error: no identifier for declarator v
velocity.d:110: error: semicolon expected, not '*='
velocity.d:110: error: Declaration expected, not '*='


class Velocity
{
private:

	float _Y = 0.0;
	float _X = 0.0;

public:
	this (float x, float y )
	{
		_Y = y;
		_X = x;
	}

	ref Velocity opOpAssign(string op) ( in float multiplier )
	if( op == "*" )
	{
		_Y *= multiplier;
		_X *= multiplier;
		return this;
	}
}

version(unittest)
{
	Velocity v = new Velocity( 2.0f, 5.0f );
	v *= 5.0f;  // <- line 110
	printf( "v = %s\n", to!string(v) );
}


More information about the Digitalmars-d-learn mailing list