digitalmars.D.learn - C style function pointers
- nikki (31/31) Aug 26 2014 I am trying top port this code :
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (3/10) Aug 26 2014 You need to put an `&` before the function name:
- nikki (1/1) Aug 26 2014 thanks, that worked, I need to grow a feeling for those * and &
- ketmar via Digitalmars-d-learn (4/7) Aug 26 2014 you need to use '&' to get function pointer. i.e.
I am trying top port this code :
float interpolate( float from, float to, float amount, float
(*easing)(float) )
{
return from + ( to-from )*( easing( amount ) );
}
float linear_interpolation( float p )
{
return p;
}
the "float (*easing)(float) " part needs to be rewritten as
"float function(float) easing" as far as I know and could find
here http://dlang.org/deprecate.html#C-style function pointers.
so my code is written as:
import std.stdio;
float interpolate(float from, float to, float amount, float
function(float) easing)
{
return from + (to - from) * (easing(amount));
}
float lineair_interpolation(float p)
{
return p;
}
void main()
{
writeln(interpolate(100,100,10, lineair_interpolation));
}
this errors witha : Error: function test.lineair_interpolation
(float p) is not callable using argument types (), but I don't
really know where to go from here.
Aug 26 2014
On Tuesday, 26 August 2014 at 12:26:45 UTC, nikki wrote:
void main()
{
writeln(interpolate(100,100,10, lineair_interpolation));
}
this errors witha : Error: function test.lineair_interpolation
(float p) is not callable using argument types (), but I don't
really know where to go from here.
You need to put an `&` before the function name:
writeln(interpolate(100,100,10, &lineair_interpolation));
Aug 26 2014
thanks, that worked, I need to grow a feeling for those * and &
Aug 26 2014
On Tue, 26 Aug 2014 12:26:43 +0000 nikki via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:this errors witha : Error: function test.lineair_interpolation (float p) is not callable using argument types (), but I don't really know where to go from here.you need to use '&' to get function pointer. i.e. writeln(interpolate(100,100,10, &lineair_interpolation));
Aug 26 2014









"nikki" <nikkikoole gmail.com> 