Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ typeid()

Name: Anonymous 2006-01-11 12:59

Does anyone know how typeid() is implemented in C++???
I mean, how do I make a function like typeid() where I can pass the TYPE as a paramter.

Example:
int main()
{
    typeid(int);//<-- works of course
    f(int);//<-- how to do something like this
           //        without using macros or templates
}

Name: Anonymous 2006-01-13 18:52

>>25

As >>21 said, that information lives in the v-tables.  AFAIK, *only* in the V-tables.  V-tables are not part of the standard language, but rather an implementation detail.  There is no standard or portable way to get what you want.  Period.  End of story.  C++ has no reflection or introspection capabilities.  Period.

You can not get a pointer to some arbitrary language construct that represents a type.  Period.  No facility exists for that within the entire language.

As has been stated previously, introspection is a very high-level language concept.  A language that's close to the silicon, like C or C++, is unlikely to expose such things.

(And wrapping all your classes to accomplish this idea is rather silly and probably quite inefficient.  If you're doing anything useful with those wrappers, anyhow.)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List