Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MessageBox

Determining a variable's type

This topic is 5556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to determine the type of a variable, something likE:
int    a = 12;
//float  a = 234.4f;

//VECTOR a = VECTOR(0.0f, 1.0f, 0.0f);


// pseudocode

if (a == int)
    cout<<"int";
else if (a == float)
    cout<<"float";
else if (a == VECTOR)]
   cout<<"VECTOR";
else
   cout<<"Unknown type";

Share this post


Link to post
Share on other sites
Advertisement
I once thought I needed to do RTTI and looked at it, got code examples and was then warned that it adds quite a bit of overhead,something to do with when the program is compiling. If you have a valid reason for using RTTI then fine, you switch it on somewhere in your project options if I remember correctly, but if possible think why you are doing it before trying it.

[edited by - hammerstein_02 on September 25, 2003 4:05:01 AM]

Share this post


Link to post
Share on other sites
typeid doesnt add any overhead to types that can be evaluated at compile-time, ie int.
When using RTTI (that is, dynamic_cast and typeid on pointers/references to objects in a inheritancee tree) a very small overhead will be added. The type-info would be added to the class'' vtable, thus not doing any overhead at all, providing the class already has a vtable (else, a vptr will be added). But any object of a class thats in a inheritance-tree should have at least one virtual function, and thereby a vptr and vtable, so rtti has very little overhead.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!