按字符串名称访问 [英] Access by string name

查看:88
本文介绍了按字符串名称访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想知道是否可以访问变量

,其名称存储在另一个字符串变量。

例如:


int myInt = 10;

char * myName =" myInt";


是否可以通过myName访问myInt?


谢谢。

解决方案

jz< je ******* @ comcast.netwrote:


我想知道它是否是'可以访问变量

,其名称存储在另一个字符串变量中。

例如:


int myInt = 10;

char * myName =" myInt";


是否可以通过myName访问myInt?



不确定,但我认为不是。据我所知,在编译(链接)之后,

名称消失了。但是我认为你可以实现类似

这样的东西,不应该那么难......

Flo


3月8日,下午12:47,jz< jessec ... @ comcast.netwrote:





我想知道是否可以访问变量

,其名称存储在另一个字符串变量中。

例如:


int myInt = 10;

char * myName =" myInt" ;;



可能我需要更好地理解你的问题。 ?

您是否询问编译器(内部)如何跟踪每个

变量或类似的事件?


>

是否可以通过myName访问myInt?


谢谢。



--Raxit


我认为Java通过反射完成了这项工作,所以选择那种语言

将节省很多时间。

On 3 ??8è?,????4ê±12·?, Florian Weingarten< f ... @ go..ccwrote:


jz< jessec ... @ comcast.netwrote:


I ''想知道是否可以访问变量

,其名称存储在另一个字符串变量中。

例如:


int myInt = 10;

char * myName =" myInt" ;;


是否可以通过myName访问myInt?



不确定,但我认为不是。据我所知,在编译(链接)之后,

名称消失了。但我认为你可以实现类似

这样的东西,不应该那么难......


Flo



Hi,

I''d like to know whether it''s possible to access a variable
by its name of which is stored in another string variable.
For example:

int myInt=10;
char *myName="myInt";

Is it possible to access myInt only through myName?

Thanks.

解决方案

jz <je*******@comcast.netwrote:

I''d like to know whether it''s possible to access a variable
by its name of which is stored in another string variable.
For example:

int myInt=10;
char *myName="myInt";

Is it possible to access myInt only through myName?

Not sure, but I think no. As far as I know, after compiling (linking),
the names are gone. But I think you could implement something like
that by yourself, should not be that hard..
Flo


On Mar 8, 12:47 pm, jz <jessec...@comcast.netwrote:

Hi,

I''d like to know whether it''s possible to access a variable
by its name of which is stored in another string variable.
For example:

int myInt=10;
char *myName="myInt";

May be I need to better understand your question. ?
Are you asking how compiler (internally) tracking occurence of each
Variable or something like that ?

>
Is it possible to access myInt only through myName?

Thanks.

--Raxit


I think Java have done the job by reflection, so choose that language
will save a lot time.
On 3??8è?, ????4ê±12·?, Florian Weingarten <f...@go..ccwrote:

jz <jessec...@comcast.netwrote:

I''d like to know whether it''s possible to access a variable
by its name of which is stored in another string variable.
For example:

int myInt=10;
char *myName="myInt";

Is it possible to access myInt only through myName?


Not sure, but I think no. As far as I know, after compiling (linking),
the names are gone. But I think you could implement something like
that by yourself, should not be that hard..

Flo



这篇关于按字符串名称访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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