Define C ++ function at runtime

I'm trying to adjust some math code that I wrote to allow arbitrary functions, but I can only do this by pre-defining them at compile time, which seems awkward. I am currently using function pointers, but as far as I can see, the same problem would occur with functors. To provide a simplified example, the following code is used for forward difference differentiation:

double xsquared(double x) {
    return x*x;
}

double expx(double x) {
    return exp(x);
}

double forward(double x, double h, double (*af)(double)) {
    double answer = (af(x+h)-af(x))/h;

    return answer;  
}

If one of the first two functions can be passed as the third argument. However, I would like the user to enter the user password (in actual C ++), instead of having to pre-configure the functions. Any help would be greatly appreciated!

+3
8

, , ++. , ++ (, Lua Python C/++, ) , , , .. .

Clang - , Apple, LLVM. Clang , , ++, . , , , Clang - , .

, ClamAV , C.

, , GCC . , GCC , GCC , . , .

+4

++ - , , . , . , .

+3

, . , , , .

, , , ++ .

+1

, lua ​​ python . . .

+1

++, , Perl, .

- , .

0

, , :

0

C (libtcc).

, C ++.

, :

  • DLL
  • DLL
  • .
0

, , ++ c, , , . - , postfix. , , HP STL. 30 :

http://www.speqmath.com/tutorials/expression_parser_cpp/index.html

: "gcc 'parser' infix to postfix"

0

Source: https://habr.com/ru/post/1791060/


All Articles