我应该使用RTTI吗? [英] Should I use RTTI?

查看:93
本文介绍了我应该使用RTTI吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我有一个问题,这比理论更具理论性。我需要知道RTTI的好处。
我看到另一种做法...


A级{

公开:

~virtual A(){}


enum输入{X,Y,Z};


类型GetType(){return type_; }


私人:

类型type_;

}


B类:公共A {...}

现在,如果我想知道它是什么类型的类,我只需要调用一个

GetType方法。


我对任何建议都很满意。谢谢。

Well I''ve got a problem, that is more theoretical than practital. I
need to know benefits of RTTI. I see another way of doing it...

class A {
public:
~virtual A() {}

enum Type { X, Y, Z };

Type GetType() { return type_; }

private:
Type type_;
}

class B : public A { ... }

and now if I want to know what type of class it is I just call a
GetType method.

I''d be really pleased with any advice. Thanks.

推荐答案

ms **** @ gmail.com 写道:

嗯,我有一个问题,这比理论更具理论性。我需要知道RTTI的好处。
我看到另一种做法...


A级{

公开:

~virtual A(){}


enum输入{X,Y,Z};


类型GetType(){return type_; }


私人:

类型type_;

}


B类:公共A {...}

现在,如果我想知道它是什么类型的类,我只需要调用一个

GetType方法。


我对任何建议都很满意。谢谢。
Well I''ve got a problem, that is more theoretical than practital. I
need to know benefits of RTTI. I see another way of doing it...

class A {
public:
~virtual A() {}

enum Type { X, Y, Z };

Type GetType() { return type_; }

private:
Type type_;
}

class B : public A { ... }

and now if I want to know what type of class it is I just call a
GetType method.

I''d be really pleased with any advice. Thanks.



完全适用于一组已知的类型。


-

Ian柯林斯。

Perfectly valid for a known set of types.

--
Ian Collins.


Ian Collins写道:
Ian Collins wrote:
ms **** @ gmail.com 写道:
ms****@gmail.com wrote:

>>嗯,我有一个问题,这比理论更重要practital。我需要知道RTTI的好处。我看到了另一种做法...

A类{
公开:
〜虚拟A(){}

枚举类型{X ,Y,Z};

输入GetType(){return type_; }

私人:
类型type_;
}

B类:公共A {...}

和现在,如果我想知道它是什么类型的类,我只需要调用一个
GetType方法。

我对任何建议都非常满意。谢谢。
>>Well I''ve got a problem, that is more theoretical than practital. I
need to know benefits of RTTI. I see another way of doing it...

class A {
public:
~virtual A() {}

enum Type { X, Y, Z };

Type GetType() { return type_; }

private:
Type type_;
}

class B : public A { ... }

and now if I want to know what type of class it is I just call a
GetType method.

I''d be really pleased with any advice. Thanks.



完全适用于一组已知的类型。


Perfectly valid for a known set of types.



我忘了指出GetType ()应该是虚拟的。


-

Ian Collins。

I forgot to point out that GetType() should be virtual.

--
Ian Collins.


ms **** @ gmail.com 写道:

嗯我已经遇到了问题,这比实际问题更具理论性。我需要知道RTTI的好处。
我看到另一种做法...


A级{

公开:

~virtual A(){}


enum输入{X,Y,Z};


类型GetType(){return type_; }


私人:

类型type_;

}


B类:公共A {...}

现在如果我想知道它是什么类型的类我只需要调用一个

GetType方法。
Well I''ve got a problem, that is more theoretical than practital. I
need to know benefits of RTTI. I see another way of doing it...

class A {
public:
~virtual A() {}

enum Type { X, Y, Z };

Type GetType() { return type_; }

private:
Type type_;
}

class B : public A { ... }

and now if I want to know what type of class it is I just call a
GetType method.



您的方法需要程序员进行某种类型的维护。

内置的typeid工具为你带来了所有的魔力。


我想你可以用模板构建类似的东西但是然后为什么 ?

Your method requires some type of maintenance by the programmer. The
built-in typeid facility does all the magic for you.

I suppose you could build somthing similar out of templates but then "why" ?


这篇关于我应该使用RTTI吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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