我可以使用字符串来创建对象吗? [英] Can I use a string to create a object?

查看:89
本文介绍了我可以使用字符串来创建对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我现在有个问题。我可以使用字符串来创建对象吗?

例如,我有一个函数


void fun(cha * str)


str是类型的名称。如果我调用函数fun(" int"),怎么做

我创建一个int类型变量。如果有一个类名classtype,我

也调用函数fun(classtype),如何创建一个classtype

类型变量?


谢谢

解决方案

dolphin写道:


大家好

我现在有一个问题。我可以使用字符串来创建对象吗?

例如,我有一个函数


void fun(cha * str)


str是类型的名称。如果我调用函数fun(" int"),怎么做

我创建一个int类型变量。如果有一个类名classtype,我

也调用函数fun(classtype),如何创建一个classtype

类型的变量?



见昨天''s thread' '是否有任何'"'''反字符串化运算符#""""。


-

Ian Collins。


On 12 ??14è?,????4ê±47·?, Ian Collins< ian-n ... @ hotmail.comwrote:
< blockquote class =post_quotes>
dolphin写道:


嗨全部

我现在有一个问题。我可以使用字符串来创建对象吗?

例如,我有一个函数


void fun(cha * str)


str是类型的名称。如果我调用函数fun(" int"),怎么做

我创建一个int类型变量。如果有一个类名classtype,我

也调用函数fun(classtype),如何创建一个classtype

类型的变量?



请参阅昨天的''主题''是否有任何"""< Anti Stringizing operator#""""。


-

Ian Collins。



你的意思是我不能用C ++做这个吗?


dolphin写道:


On 12 ??14è?,????4ê±47·?, Ian Collins< ian-n ... @ hotmail.comwrote:


> dolphin写道:


>>大家好我现在有一个问题。我可以使用字符串来创建对象吗?
例如,我有一个函数
void fun(cha * str)
str是一个类型的名称。如果我调用函数fun(int),我如何创建一个int类型变量。如果有一个类名classtype,我也会调用函数fun(" classtype" ),如何创建一个classtype
类型的变量?


参见昨天的''主题''是否有任何"""反字符串化运算符#""""。



*请*不要引用签名。


>

你是说我不能用C ++做到这一点?



不是直接的,没有。阅读工厂模式及其在C ++中的使用。


-

Ian Collins。


Hi All
I have a question now. Can I use a string to create a object?
For example ,I have a function

void fun(cha *str)

the str is a name of a type. If I call the function fun("int"),how do
I create a int type variable.And if there is a class name classtype, I
also call the function fun("classtype"),how do I create a classtype
type variable?

Thanks

解决方案

dolphin wrote:

Hi All
I have a question now. Can I use a string to create a object?
For example ,I have a function

void fun(cha *str)

the str is a name of a type. If I call the function fun("int"),how do
I create a int type variable.And if there is a class name classtype, I
also call the function fun("classtype"),how do I create a classtype
type variable?

See yesterday''s thread ''Is there any """Anti Stringizing operator #"""".

--
Ian Collins.


On 12??14è?, ????4ê±47·?, Ian Collins <ian-n...@hotmail.comwrote:

dolphin wrote:

Hi All
I have a question now. Can I use a string to create a object?
For example ,I have a function

void fun(cha *str)

the str is a name of a type. If I call the function fun("int"),how do
I create a int type variable.And if there is a class name classtype, I
also call the function fun("classtype"),how do I create a classtype
type variable?


See yesterday''s thread ''Is there any """Anti Stringizing operator #"""".

--
Ian Collins.

Do you mean that I can not do this in C++?


dolphin wrote:

On 12??14è?, ????4ê±47·?, Ian Collins <ian-n...@hotmail.comwrote:

>dolphin wrote:

>>Hi All
I have a question now. Can I use a string to create a object?
For example ,I have a function
void fun(cha *str)
the str is a name of a type. If I call the function fun("int"),how do
I create a int type variable.And if there is a class name classtype, I
also call the function fun("classtype"),how do I create a classtype
type variable?

See yesterday''s thread ''Is there any """Anti Stringizing operator #"""".

*Please* don''t quote signatures.

>
Do you mean that I can not do this in C++?

Not directly, no. Read up on the factory pattern and its use in C++.

--
Ian Collins.


这篇关于我可以使用字符串来创建对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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