www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - UFCS on Enum in Member Function

reply jmh530 <john.michael.hall gmail.com> writes:
I have been working with some C error codes that are organized in 
an enum. I noticed that if I tried to write a function that 
processes these error codes within a struct, then I could not use 
a UFCS-style call.

For instance, in the code below, I could use Baz but not Caz. It 
seems to work when I use the alternate version of Caz calling a 
non-member function.

Bug?


enum X
{
	A = 1,
}

struct Foo
{
	X Bar(X x)
	{
		return x;
	}
	
	X Baz()
	{
		auto result = X.A;
		return Bar(result);
	}
	
	/*
	X Caz()
	{
		auto result = X.A;
		return result.Bar();
	}
	*/
	
	X Caz_alt()
	{
		auto result = X.A;
		return result.Bar_alt();
	}
}

X Bar_alt(X x)
{
	return x;
}

void main()
{
	auto foo = Foo();
	auto result = foo.Baz();
	//auto result2 = foo.Caz();
	auto result3 = foo.Caz_alt();
}
Feb 09 2016
parent anonymous <anonymous example.com> writes:
On Tuesday, 9 February 2016 at 21:05:50 UTC, jmh530 wrote:
 For instance, in the code below, I could use Baz but not Caz. 
 It seems to work when I use the alternate version of Caz 
 calling a non-member function.

 Bug?
No bug; works as intended. UFCS can only be used with free functions, not with methods.
Feb 09 2016