Modify Function Pointer to Take Additional Parameters

Kagamin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 19 06:21:26 PST 2016


On Friday, 19 February 2016 at 05:41:01 UTC, jmh530 wrote:
> void main()
> {
> 	import std.stdio : writeln;
>
> 	auto foo_bar = foo(&bar);
> 	
> 	writeln(qux(1, 2, foo_bar)); //compiler error
> 	writeln(qux(1, 2, &baz));
> }

int bar(int x)
{
	return x;
}

int baz(int x, int y)
{
	return bar(x);
}

void main()
{
	import std.stdio : writeln;

	int function(int x, int y) foo_bar = &baz;
	
	writeln(foo_bar(1, 2));
}



More information about the Digitalmars-d-learn mailing list