如何将函数签名作为输入传递以初始化 C++ 中的另一个函数?
How to pass a function signature as input in order to initialize another function in C++?
我的问题如下:假设我有一个用 C++ 编写的程序,它接受一个函数并给出它的积分。在这个程序中,我在源代码中手动编写函数,每次我想集成另一个函数时我都会更改它的签名。如果现在我想在输入中初始化这个函数(比如给一个字符串),以便在编译时直接初始化它,我该怎么办?
我会对这样的东西感兴趣:
$ ./program
$ Give me the function name: x+3y+4
现在函数初始化为:
int func() { return x+3y+4; }
你需要这个:https://github.com/ArashPartow/exprtk
只比用本地代码编译表达式慢一点。
还有其他的,你可以在这里看到大部分:https://github.com/ArashPartow/math-parser-benchmark-project
(免责声明:我是 Node.js 绑定的作者:https://github.com/mmomtchev/exprtk.js)
我的问题如下:假设我有一个用 C++ 编写的程序,它接受一个函数并给出它的积分。在这个程序中,我在源代码中手动编写函数,每次我想集成另一个函数时我都会更改它的签名。如果现在我想在输入中初始化这个函数(比如给一个字符串),以便在编译时直接初始化它,我该怎么办?
我会对这样的东西感兴趣:
$ ./program
$ Give me the function name: x+3y+4
现在函数初始化为:
int func() { return x+3y+4; }
你需要这个:https://github.com/ArashPartow/exprtk
只比用本地代码编译表达式慢一点。
还有其他的,你可以在这里看到大部分:https://github.com/ArashPartow/math-parser-benchmark-project
(免责声明:我是 Node.js 绑定的作者:https://github.com/mmomtchev/exprtk.js)