C ++元编程语言 [英] C++ Meta Programming language

查看:97
本文介绍了C ++元编程语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用某种类型的面向对象的
框架创建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 < br $>
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 oriented
framework that is designed to be used to create C++ applications?

something like maybe

new 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 the
pre-processor to insert C++ code somewhere

like in a normal c++ program:
#include <iostream>

using namespace std;

#code
new 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; }");
#endcode

blah...

void main(void)
{

#code
code("class1 c");
#endcode

c.Name("Hello");

//or if you wanted you could just put that in the #code block as
code("c.Name("Hello");");
}

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.
Anything like that out there?

Thanks

Jon

解决方案


"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?

REH


On 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 literally
create and execute classes on the fly. I have actually done this in
python (for example). In an interpreted language, you just need to
generate the strings, and eval them.

Any object system where classes were objects (so you could instantiate
them and dynamically add state to the *classes*) would also make this
easier.

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, or
developing some sort of prototype system (classes-as-objects) might
be appropriate. The more complicated the prototype model gets, the
closer 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 message
news: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?

REH



because there are some things I have to do that is much more work to do by
hand... the classes example is just an example and not necessarily what I
need to do. Ofcourse you should know why its easier... this is one of the
reasons 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 ++元编程语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆