本文介绍了C ++元编程语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 有没有办法使用某种类型的面向对象的框架创建c ++代码,该框架旨在用于创建C ++应用程序? something喜欢也许 新class1; class1.add_class(" first_class"," base_class"); class1。 add_private_data(" char *"," name"); class1.add_public_member(" void"," Name"," const char * n"," {name = n;}"); 可能会创建以下C ++代码 " class first_class:base_class { private: char * name; public: void Name(const char * n) { name = n; } }; " 或其他...... 甚至是C ++的修改版,其中包含一个告诉的关键字预处理器在某处插入C ++代码 就像在一个普通的c ++程序: #include< iostream> 使用命名空间std; #code new class1; class1.add_class(" first_class"," base_class"); class1.add_private_data(" char *" ;,"; class1.add_public_member(" void"," Name"," const char * n"," {name = n; }"); #endcode blah ... void main(void) { #code code(" class1 c"); #endcode c.Name(" Hello"); //或者如果你想要你可以把它放在#code块中作为 代码(" c.Name(" Hello");"); } 或其他什么..基本上,我有一些具体的事情我需要做,而且它好像b ++ b似乎c ++语言不能让它们变得容易(并且它们不是真的值得的。)通过C ++中的手来做...)但是如果我能告诉程序 预处理器稍微做一些简单的事情(比如插入一些代码 某个地方(虽然一次在多个地方)然后这将是一个地狱的b / b 很容易。 那里有类似的东西吗? 谢谢 Jon 解决方案 " Jon Slaughter" <乔*********** @ Hotmail.com>在消息中写道 新闻:11 ************* @ corp.supernews.com ... 或其他...... Basicaly我有一些我需要做的具体事情,而且似乎c ++语言并不容易做到(而且在C ++中用手做的事情并不值得。) ..但如果我能告诉程序预处理器有点做一些简单的事情(比如在某个地方插入一些代码(虽然一次在多个地方)然后它会变得更容易。 为什么你认为动态定义类更容易? 告诉压缩器这样做,然后自己定义它们? REH 2005-07-02,Jon Slaughter< Jo ********** *@Hotmail.com>写道:有没有办法使用某种类型的面向对象框架来创建c ++代码,该框架旨在用于创建C ++ 使用解释语言更容易做到这一点 - 你可以实际上 即时创建和执行类。我实际上是在 $中完成的b $ b python(例如)。在解释语言中,你只需要生成字符串,然后评估它们。 任何对象系统CL asses是对象(所以你可以实例化它们并动态地向*类添加状态*)也会使这个 更容易。 基本上,你要做的是与C ++ 对象模型的工作方式不一致,这就是为什么C ++并不容易。 根据您要做的事情,动态加载,或者开发某种原型系统(类作为对象)的可能是 是合适的。原型模型越复杂, 就越接近于在C ++之上构建不同的对象模型。 干杯, - Donovan Rebbechi http ://pegasus.rutgers.edu/~elflord/ " REH" < me@you.com>在消息中写道 news:6n ************** @ twister.nyroc.rr.com ... Jon Slaughter <乔*********** @ Hotmail.com>在消息中写道新闻:11 ************* @ corp.supernews.com ... 或者其他......基本我有一些具体的我需要做的事情和它似乎c ++语言不容易做(并且它们在C ++中用手做的时候并不值得......)但是如果我可以告诉程序预处理器有点做一些简单的事情(比如在某个地方插入一些代码(虽然一次在多个地方)然后它会变得更容易。 为什么你认为动态定义你的类更容易,或者告诉压缩器这样做,然后自己定义它们? REH 因为有一些我需要做的事情还有很多工作要做 hand ...类示例只是一个例子,并不一定是我需要做的事情。当然你应该知道为什么它更容易......这是为什么C ++的原因之一?有模板,许多人使用它们(因为它是一种定义类的动态方式,并且更容易做到)。 is there any way to create c++ code using some type of objected orientedframework that is designed to be used to create C++ applications?something like maybenew class1;class1.add_class("first_class", "base_class");class1.add_private_data("char *", "name");class1.add_public_member("void", "Name", "const char *n", "{ name = n; }");might create the following C++ code"class first_class : base_class{private:char *name;public:void Name(const char *n){name = n;}};"or whatever...or even a modification of C++ that has a keyword that tells thepre-processor to insert C++ code somewherelike in a normal c++ program:#include <iostream>using namespace std;#codenew class1;class1.add_class("first_class", "base_class");class1.add_private_data("char *", "name");class1.add_public_member("void", "Name", "const char *n", "{ name = n; }");#endcodeblah...void main(void){#codecode("class1 c");#endcodec.Name("Hello");//or if you wanted you could just put that in the #code block ascode("c.Name("Hello");");}or whatever... Basicaly I have some specific things I need to do and itseems that the c++ language does not make them easy to do(and they are notreally worth while to do by "hand" in C++)... but if I could tell "program"the pre-processor a little to do some simple things(like insert some codesomewhere(though at multiple places at once) then it would be a hell of alot easier.Anything like that out there?ThanksJon 解决方案"Jon Slaughter" <Jo***********@Hotmail.com> wrote in messagenews:11*************@corp.supernews.com... or whatever... Basicaly I have some specific things I need to do and it seems that the c++ language does not make them easy to do(and they are not really worth while to do by "hand" in C++)... but if I could tell "program" the pre-processor a little to do some simple things(like insert some code somewhere(though at multiple places at once) then it would be a hell of a lot easier.Why do you think it would be easier to dynamically define your classes ortell the propressor to do it, then to just define them yourself?REHOn 2005-07-02, Jon Slaughter <Jo***********@Hotmail.com> wrote: is there any way to create c++ code using some type of objected oriented framework that is designed to be used to create C++Much easier to do this with interpreted languages -- you can literallycreate and execute classes on the fly. I have actually done this inpython (for example). In an interpreted language, you just need togenerate the strings, and eval them.Any object system where classes were objects (so you could instantiatethem and dynamically add state to the *classes*) would also make thiseasier.Basically, what you''re trying to do is at odds with the way the C++object model works, which is why C++ doesn''t make it easy.Depending on what you''re trying to do, either dynamic loading, ordeveloping some sort of prototype system (classes-as-objects) mightbe appropriate. The more complicated the prototype model gets, thecloser you are to building a different object model on top of C++.Cheers,--Donovan Rebbechi http://pegasus.rutgers.edu/~elflord/"REH" <me@you.com> wrote in messagenews:6n**************@twister.nyroc.rr.com... "Jon Slaughter" <Jo***********@Hotmail.com> wrote in message news:11*************@corp.supernews.com... or whatever... Basicaly I have some specific things I need to do and it seems that the c++ language does not make them easy to do(and they are not really worth while to do by "hand" in C++)... but if I could tell "program" the pre-processor a little to do some simple things(like insert some code somewhere(though at multiple places at once) then it would be a hell of a lot easier. Why do you think it would be easier to dynamically define your classes or tell the propressor to do it, then to just define them yourself? REHbecause there are some things I have to do that is much more work to do byhand... the classes example is just an example and not necessarily what Ineed to do. Ofcourse you should know why its easier... this is one of thereasons why C++ has templates and many people use them(because it is a"dynamic" way of defining classes and is much easier to do). 这篇关于C ++元编程语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 05:49
查看更多