Thread: RTTI - typeid()

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    99

    RTTI - typeid()

    Code:
    #include<iostream>
    #include<typeinfo>
    using namespace std;
    
    class A{};
    
    int main()
    {
        A a;
        cout<<typeid(a).name();    
        return 0;                    
    }
    i am getting 1A as output, i expected A ??

  2. #2
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Maybe "1A" is the linker name for your A class?

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I've read that the C-style string you get back from name() in this case is non-portable between compilers.... basically implemetation dependent....

    Just running a few test programs through MinGW for a second, the number in the first byte always seems to match the number of letters in the class name, which I would guess is the length, in bytes, necessary to hold the class name. I imagine someone better versed in these details would be better able to tell us something more definite.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RTTI for distribution
    By coletek in forum C++ Programming
    Replies: 6
    Last Post: 09-13-2010, 10:05 AM
  2. how to uuse 'typeid'
    By John_L in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2008, 07:44 PM
  3. typeid problem
    By mikahell in forum C++ Programming
    Replies: 13
    Last Post: 12-03-2006, 06:35 PM
  4. Debug function using typeid?
    By screemfead in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2006, 10:42 AM
  5. Typeid and Templates
    By Trauts in forum C++ Programming
    Replies: 6
    Last Post: 04-09-2003, 08:55 PM