如何从c ++运行c ++代码? [英] How to run c++ code from c++?
本文介绍了如何从c ++运行c ++代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在c ++程序中有一些c ++代码作为字符串数量(数据),我可以执行该字符串的内容吗?
解决方案
简短答案:不能。
稍长一点的答案:c ++没有反射,一般编译,所以不支持这种类型
- >
- 使用可嵌入的动态语言,如[python | tcl | ruby | ...]与您的c ++代码一致。现在,您需要在数据中使用动态语言(而不是c ++)。
- 使用c ++解释器,例如 cint 或ch。
- 使用系统c ++编译器从您的代码构建一个动态库,并链接到它。危险和系统依赖。
- 使用其他语言。
If I have some c++ code as a string quantity (data) in a c++ program, can I execute the contents of that string?
As using the CodeDOM in C# or the eval function present in perl, python, etc..
解决方案
Short answer: you can't.
Slightly longer answer: c++ has no reflection, and is generally compiled, so there so is no support for this kind of thing, and it can not be easily added..
Work arounds:
- Use an embeddable dynamic language like [python|tcl|ruby|...] in concert with your c++ code. Now you need to have the dynamic language (rather then c++) in the data.
- Use a c++ interpreter like cint or ch. This binds you to the interpreter.
- Use the system c++ compiler to construct a dynamic library from your code and link to it on the fly. Risky and system dependent.
- Use a different language.
这篇关于如何从c ++运行c ++代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文