RTTI Question: typeid() for structures

  • Thread starter Generic Usenet Account
  • Start date
G

Generic Usenet Account

My C++ compiler (gcc 3.3.1) is prefixing a number in front on a
user-defined structure when I invoke typeid() on it. Can anyone
explain why? [Look at the funny thing I have to do in the macro
definition to get rid of that]

Source code follows:
Bhat

////////////////////////////////////////////////
#include <iostream>
#include <typeinfo>
#include <strings.h>

using namespace std;

#define TYPEID(x) cout << #x << ": " << strpbrk(typeid(x).name(),
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") << endl;


struct sampleStruct
{
char c;
short s;
int i;
};

int
main()
{
TYPEID(sampleStruct);

sampleStruct whatsmytype;
TYPEID(whatsmytype);
}
 
D

Dave

The C++ implementation may return anything it wants when name() is called.
It could be a human-friendly name, a mangled name, a curse word, an empty
string, your mothers maiden name, etc...
 
D

Dave

Generic Usenet Account said:
My C++ compiler (gcc 3.3.1) is prefixing a number in front on a
user-defined structure when I invoke typeid() on it. Can anyone
explain why? [Look at the funny thing I have to do in the macro
definition to get rid of that]

Source code follows:
Bhat

////////////////////////////////////////////////
#include <iostream>
#include <typeinfo>
#include <strings.h>

using namespace std;

#define TYPEID(x) cout << #x << ": " << strpbrk(typeid(x).name(),
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") << endl;


struct sampleStruct
{
char c;
short s;
int i;
};

int
main()
{
TYPEID(sampleStruct);

sampleStruct whatsmytype;
TYPEID(whatsmytype);
}

The C++ implementation may return anything it wants when name() is called.
It could be a human-friendly name, a mangled name, a curse word, an empty
string, your mothers maiden name, etc...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,059
Members
48,769
Latest member
Clifft

Latest Threads

Top