• Welcome to Valhalla Legends Archive.
 

Type Indentification C++

Started by TheNewOne, August 20, 2005, 10:01 PM

Previous topic - Next topic

TheNewOne

I was wondering how possible it is to get c++ to split up a given "thing" or object according to type. I dunno exatly hwo to explain this correctly, but like identify if what ur feeding it is a const char an int or a long etc. Picking correct types. so to speak. Any help is appreciated.

Mangix

...what do you mean split a given thing?

sepperate a string in 2 strings?

TheNewOne

no what i mean is to identify it is a string. or to identify it is a integer. for example a user typing something in a control. Then to allocate i some space and give it a type as const char or int etc. if you egt what i mean its hard to explain.

Kp

Until you figure out how to explain what you want, I doubt anyone will give you a good answer.  In hopes that this helps: C++ is a strongly typed language.  You must use a type which makes sense for the expression being examined, or you'll get a warning (or more likely, an error).  User input comes in the form of strings.  You might restrict it to contain only digits, but it's still a string from the language's perspective.  It's your problem to convert it to a number.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

R.a.B.B.i.T

I think he is looking for a C++ equivolent of VB6's VarType() function?

MyndFyre

Quote from: Kp on August 21, 2005, 01:12 AM
Until you figure out how to explain what you want, I doubt anyone will give you a good answer.  In hopes that this helps: C++ is a strongly typed language.  You must use a type which makes sense for the expression being examined, or you'll get a warning (or more likely, an error).  User input comes in the form of strings.  You might restrict it to contain only digits, but it's still a string from the language's perspective.  It's your problem to convert it to a number.

I think he's looking for an equivalent to C#'s typeof() and objExpr.GetType() functions.  This would be applicable when you're using a framework such as wxWidgets or MFC, where (for example) MFC classes all derive from CObject.  Sure, you can static_cast or dynamic_cast to CObject, but you're not going to get a lot of functionality from it.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

shout

If you are looking for strictly simple numerical types use the sizeof() operator. Also look into templates, these may be of help to you.

K

You can use the typeid() operator (assuming RTTI is enabled) to determine the type of a variable at run time.  Of course, I don't think this is going to help for what you want to do.

TheNewOne

#8
Quote from: MyndFyre on August 21, 2005, 02:44 AM
I think he's looking for an equivalent to C#'s typeof() and objExpr.GetType() functions. This would be applicable when you're using a framework such as wxWidgets or MFC, where (for example) MFC classes all derive from CObject. Sure, you can static_cast or dynamic_cast to CObject, but you're not going to get a lot of functionality from it.

yes Myndfyre thats exactly the type of thing im looking for. Does C++ have an equivalent by any chance. Or any idea on how i would go about making my own function to determine this?

Adron

Quote from: TheNewOne on August 21, 2005, 08:07 PM
yes Myndfyre thats exactly the type of thing im looking for. Does C++ have an equivalent by any chance. Or any idea on how i would go about making my own function to determine this?

In C++ you mostly already know what type a variable is. The exception is when you have a class hierarchy and want to know whether something is a base class or one of the derived classes. But I doubt that applies to what you're doing...

Particularly, if a user has typed some input into a textbox, the variable containing it will be a string. Until you convert it to something else. It won't magically turn into an integer just because it contains only numbers.

TheNewOne

This is a company made OS platform which its textbox like control does not always have as a string. It sends and returns different types according to which is typed. Now i was wondering if there is anything in existence that can help me out at all here. Or any way i can build a function to identify a declared variable. Or perhaps could i take the data into some place holder of some sort and then identify what it is? i am lost with this and im in serious need here. Any help would be great.

Adron

So, what does it send and return? Show some definitions!

TheNewOne

the control itself is defined as a const char, when numbers only are present it stores the type in a temp buffer as int or largfer depending ont eh size of the number. If there ar eletters it usually stays the same as const char.

Eibro

Eibro of Yeti Lovers.

Adron

Quote from: TheNewOne on August 23, 2005, 01:25 PM
the control itself is defined as a const char, when numbers only are present it stores the type in a temp buffer as int or largfer depending ont eh size of the number. If there ar eletters it usually stays the same as const char.

There must be some way the control tells you in what way it has stored the value.