converting a string function name to an actual function call
oliver
oliver.ruebenkoenig at web.de.REMOVE
Tue Nov 27 09:30:13 PST 2007
Hi everyone,
is it possible to program kind of a general function that applies the name of a function (given as a char [] ) to arguments. The following code does not work but something in the same spirit.
Thanks once more to this very patient group.
Oliver
-------
import std.stdio;
int f1( int a ) {
return a+1;
}
int f2( int b ) {
return b-10;
}
int apply(char [] name, int arg) {
return name(arg);
}
int main() {
int i = 1;
i = f1(i);
writefln("i: ",i);
i = f2(i);
writefln("i: ",i);
i = apply( "f1", i );
i = apply( "f2", i );
writefln("i: ",i);
return 0;
}
More information about the Digitalmars-d-learn
mailing list