overloading evaluation (treating objects as functions)

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 17 12:40:09 PDT 2015


On Sunday, 17 May 2015 at 18:58:32 UTC, Namespace wrote:
> http://dlang.org/operatoroverloading.html#function-call

Like this:

module main;

import std.stdio;

class F
{
	int opCall(int value)
	{
		return value * 2;
	}
}

void main(string[] args)
{
	auto f = new F();

	writeln("The value of f at 7 is ", f(7));
}


More information about the Digitalmars-d-learn mailing list