Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > RTTI

Reply
 
 
gouqizi.lvcha@gmail.com
Guest
Posts: n/a
 
      03-14-2005
Hey all,

Does standard C++ support RTTI? For example, I would like to
dynamically
get a class's name.

Rick

 
Reply With Quote
 
 
 
 
John Carson
Guest
Posts: n/a
 
      03-14-2005
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com
> Hey all,
>
> Does standard C++ support RTTI? For example, I would like to
> dynamically
> get a class's name.
>
> Rick


Yes.

--
John Carson
 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      03-14-2005
"(E-Mail Removed)" wrote:
>
> Hey all,
>
> Does standard C++ support RTTI? For example, I would like to
> dynamically
> get a class's name.
>


look up functions
typeid()
typename()
and the structure 'type_info'

--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      03-14-2005
(E-Mail Removed) wrote:

> Hey all,
>
> Does standard C++ support RTTI? For example, I would like to
> dynamically get a class's name.


Yes. Try typeid(MyClass).name()
However, the name that you get back from this is implementation defined. It
might not be the same as it is defined in your source code.

 
Reply With Quote
 
gouqizi.lvcha@gmail.com
Guest
Posts: n/a
 
      03-14-2005
Hi Rolf,

I tried. gcc 3.2 does not give the same as my source code as you said
it.
What can I do if I want to get the exactly the same name as I defined
in code?

Rick

 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      03-14-2005
(E-Mail Removed) wrote:
> Hi Rolf,
>
> I tried. gcc 3.2 does not give the same as my source code as you said
> it.
> What can I do if I want to get the exactly the same name as I defined
> in code?
>
> Rick
>


create a member function "const char * get_class_name();"
 
Reply With Quote
 
evaned@gmail.com
Guest
Posts: n/a
 
      03-14-2005
Why isn't this standardized? Implementation difficulties? Run-time
inefficiencies?

I'm sorta thinking that having the RTTI work properly for derived
classes would require all classes to have vtables, is this why?

 
Reply With Quote
 
gouqizi.lvcha@gmail.com
Guest
Posts: n/a
 
      03-14-2005
Have to do like this way.

Do you know why gcc do in such way?

 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      03-14-2005
In article <(E-Mail Removed). com>,
(E-Mail Removed) <(E-Mail Removed)> wrote:
>I tried. gcc 3.2 does not give the same as my source code as you said
>it.
>What can I do if I want to get the exactly the same name as I defined
>in code?


If I understand what you're asking, you don't, you get whatever
the _vendor_ chooses for it.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      03-15-2005
(E-Mail Removed) wrote:
> Hey all,
>
> Does standard C++ support RTTI?


Yes.
> I would like to
> dynamically
> get a class's name.
>

It however does NOT support that.
You'll have to write your own virtual method to return the class name.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[RTTI] cast base class pointer to <templated> derived class pointer tirath C++ 3 10-12-2003 01:44 PM
RTTI versus a base class enum to represent type BillyO C++ 2 09-30-2003 10:21 PM
About RTTI Steven Lien C++ 4 08-19-2003 06:03 PM
Re: RTTI John Harrison C++ 2 07-14-2003 02:36 PM
Re: RTTI Alf P. Steinbach C++ 0 07-14-2003 08:18 AM



Advertisments