UFCS on Enum in Member Function

jmh530 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 9 13:05:50 PST 2016


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();
}


More information about the Digitalmars-d-learn mailing list