overloading evaluation (treating objects as functions)

dan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 17 12:45:11 PDT 2015


Awesome!!

Thanks Gary and namespace (and obviously i gotta improve my 
google-fu).

dan

On Sunday, 17 May 2015 at 19:40:10 UTC, Gary Willoughby wrote:
> 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