存储整个命名空间 [英] Store Entire Namespace

查看:79
本文介绍了存储整个命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以某种方式保存整个命名空间?例如,

说我有这个命名空间:


foo.h

========== ========================================


namespace foo

{

int testVar1;

int testVar2

void testFunc1(void);

void testFunc2(void);

char testVar3 [1024];

};


== ================================================ <无线电通信/>

我使用它一段时间然后想要将

程序的状态写入磁盘。有没有办法复制所有命名空间

全局,而不必显式复制testVar1,testVar2和

testVar3 - 这样就不必修改代码如果

名称空间略有改变?

-

[见 http://www.gotw.ca/resources/clcm.htm 有关的信息]

[comp .lang.c ++。主持。第一次海报:做到这一点! ]

Is it possible to save an entire namespace in some way? For example,
say I have this namespace:

foo.h
==================================================

namespace foo
{
int testVar1;
int testVar2
void testFunc1(void);
void testFunc2(void);
char testVar3[1024];
};

==================================================

And I use it for a while and then want to write the state of the
program to disk. Is there some way to copy all of the namespace
globals, without having to explicitly copy testVar1, testVar2, and
testVar3 - so that the code would not have to be modified if the
namespace is slightly changed?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

推荐答案

Robby写道:
Robby wrote:

程序到磁盘。有没有办法复制所有命名空间

全局,而不必显式复制testVar1,testVar2和

testVar3 - 这样就不必修改代码如果

名称空间略有变化?

program to disk. Is there some way to copy all of the namespace
globals, without having to explicitly copy testVar1, testVar2, and
testVar3 - so that the code would not have to be modified if the
namespace is slightly changed?






-

[见 http://www.gotw。 ca / resources / clcm.htm 有关的信息]

[comp.lang.c ++。moderated。第一次海报:做到这一点! ]

No

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


文章< 11 ********************* @ p77g2000hsh.googlegroups 。 com>,
rs******@gmail.com 说......
In article <11*********************@p77g2000hsh.googlegroups. com>,
rs******@gmail.com says...

是否可以以某种方式保存整个命名空间?例如,

说我有这个命名空间:
Is it possible to save an entire namespace in some way? For example,
say I have this namespace:



[...代码省略]

[ ... code elided ]


我使用它一段时间然后想把

程序的状态写入磁盘。有没有办法复制所有命名空间

全局,而不必显式复制testVar1,testVar2和

testVar3 - 这样就不必修改代码如果

命名空间略有改变?
And I use it for a while and then want to write the state of the
program to disk. Is there some way to copy all of the namespace
globals, without having to explicitly copy testVar1, testVar2, and
testVar3 - so that the code would not have to be modified if the
namespace is slightly changed?



编号如果您使用类(或结构)而不是命名空间,它会让您获得更接近您想要的功能的
- 它至少允许你将所有变量分配给一个组。 OTOH,它仍然没有给出读/写组变量的能力

,所以你还需要修改

代码当你添加/删除变量。


-

后来,

杰里。


宇宙是自己想象的虚构。


[见 http://www.gotw.ca/resources/clcm.htm 有关的信息]

[comp.lang.c ++。moderated。第一次海报:做到这一点! ]

No. If you use a class (or struct) instead of a namespace it gets you
closer to the capabilities you want -- it at least allows you to assign
all the variables as a group. OTOH, it still doesn''t give the capability
to read/write the variables as a group, so you''d still need to modify
the code when you add/remove a variable.

--
Later,
Jerry.

The universe is a figment of its own imagination.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


{已删除引用的clc ++ m标题。 -mod}


4月23日上午10:43,Robby< rsimp ... @ gmail.comwrote:
{ Quoted clc++m banner removed. -mod }

On Apr 23, 10:43 am, Robby <rsimp...@gmail.comwrote:

是否可以以某种方式保存整个命名空间?例如,

说我有这个命名空间:


foo.h

========== ========================================


namespace foo

{

int testVar1;

int testVar2

void testFunc1(void);

void testFunc2(void);

char testVar3 [1024];


};


================================================ ==


我使用它一段时间然后想把

程序的状态写入磁盘。有没有办法复制所有命名空间

全局,而不必显式复制testVar1,testVar2和

testVar3 - 这样就不必修改代码如果

命名空间略有改变?
Is it possible to save an entire namespace in some way? For example,
say I have this namespace:

foo.h
==================================================

namespace foo
{
int testVar1;
int testVar2
void testFunc1(void);
void testFunc2(void);
char testVar3[1024];

};

==================================================

And I use it for a while and then want to write the state of the
program to disk. Is there some way to copy all of the namespace
globals, without having to explicitly copy testVar1, testVar2, and
testVar3 - so that the code would not have to be modified if the
namespace is slightly changed?



看看''使用名称空间foo''是否有助于解决您的问题。


干杯
-Vallabha

-

[见 http://www.gotw.ca/resources/clcm.htm 了解有关的信息]

[comp.lang.c ++。moderated。第一次海报:做到这一点! ]

See if ''using namespace foo'' is of some help to solve your problem.

Cheers
-Vallabha
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


这篇关于存储整个命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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