Understanding Safety of Function Pointers vs. Addresses of Functions

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 9 01:44:49 PDT 2015

On Wednesday, 8 July 2015 at 21:04:27 UTC, jmh530 wrote:
> On Wednesday, 8 July 2015 at 18:31:00 UTC, Steven Schveighoffer 
> wrote:
>> You can use a function lambda:
>> auto fp = (real a) => cos(a);
>> Note, I had to put (real a) even though I would have expected 
>> "a => cos(a)" to work.
>> -Steve
> Interesting. You have to put real because there is also a float 
> and double version of cos.

Even if there are no overloads, you'd still need to specify the 
type. That's because `a => cos(a)` is not a function, but a 
function template, and therefore can't be store in a variable.

More information about the Digitalmars-d-learn mailing list