C++ 是一种静态的编译语言,模板在编译时解析等等...
C++ is a static, compiled language, templates are resolved during compile time and so on...
但是是否可以在运行时创建一个函数,在源代码中没有描述,在编译过程中也没有转换成机器语言,这样用户就可以向它抛出源中没有预料到的数据?
But is it possible to create a function during runtime, that is not described in the source code and has not been converted to machine language during compilation, so that a user can throw at it data that has not been anticipated in the source?
我知道这不可能以一种直接的方式发生,但肯定是有可能的,有很多编程语言没有被编译,而是动态地创建了用 C 或 C++ 实现的那种东西.
I am aware this cannot happen in a straightforward way, but surely it must be possible, there are plenty of programing languages that are not compiled and create that sort of stuff dynamically that are implemented in either C or C++.
也许如果为所有原始类型创建工厂,以及将它们组织成更复杂的对象(例如用户类型和函数)的合适的数据结构,这是可以实现的吗?
Maybe if factories for all primitive types are created, along with suitable data structures to organize them into more complex objects such as user types and functions, this is achievable?
欢迎提供有关该主题的任何信息以及指向在线材料的提示.谢谢!
Any info on the subject as well as pointers to online materials are welcome. Thanks!
我知道这是可能的,更像是我对实现细节感兴趣:)
I am aware it is possible, it is more like I am interested in implementation details :)
是,当然,没有任何工具在其他答案中提到,但只是使用 C++ 编译器.
Yes, of course, without any tools mentioned in the other answers, but simply using the C++ compiler.
只需在您的 C++ 程序中执行这些步骤(在 linux 上,但在其他操作系统上必须类似)
just follow these steps from within your C++ program (on linux, but must be similar on other OS)
ofstreamsystem("c++/tmp/prog.cc -o/tmp/prog.so -shared -fPIC"); dlopen()这篇关于是否可以在 C++ 运行时动态创建函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在 C++ 中读取和操作 CSV 文件数据?How can I read and manipulate CSV file data in C++?(如何在 C++ 中读取和操作 CSV 文件数据?)
在 C++ 中,为什么我不能像这样编写 for() 循环:In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,为什么我不能像这样编写 for() 循环: for(
OpenMP 如何处理嵌套循环?How does OpenMP handle nested loops?(OpenMP 如何处理嵌套循环?)
在循环 C++ 中重用线程Reusing thread in loop c++(在循环 C++ 中重用线程)
需要精确的线程睡眠.最大 1ms 误差Precise thread sleep needed. Max 1ms error(需要精确的线程睡眠.最大 1ms 误差)
是否需要“do {...} while ()"?环形?Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?环形?)