Valhalla Legends Forums Archive | C/C++ Programming | Type Indentification C++

AuthorMessageTime
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.
August 21, 2005, 3:01 AM
Mangix
...what do you mean split a given thing?

sepperate a string in 2 strings?
August 21, 2005, 4:11 AM
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.
August 21, 2005, 4:19 AM
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.
August 21, 2005, 6:12 AM
R.a.B.B.i.T
I think he is looking for a C++ equivolent of VB6's VarType() function?
August 21, 2005, 6:29 AM
Myndfyr
[quote author=Kp link=topic=12579.msg124842#msg124842 date=1124604755]
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.
[/quote]

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.
August 21, 2005, 7:44 AM
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.
August 21, 2005, 4:15 PM
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.
August 21, 2005, 5:47 PM
TheNewOne
[quote author=MyndFyre link=topic=12579.msg124845#msg124845 date=1124610297]
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.
[/quote]

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?
August 22, 2005, 1:07 AM
Adron
[quote author=TheNewOne link=topic=12579.msg124902#msg124902 date=1124672830]
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?
[/quote]

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.
August 22, 2005, 12:51 PM
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.
August 23, 2005, 6:35 AM
Adron
So, what does it send and return? Show some definitions!
August 23, 2005, 3:15 PM
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.
August 23, 2005, 6:25 PM
Eibro
boost::any?
August 26, 2005, 6:37 PM
Adron
[quote author=TheNewOne link=topic=12579.msg125075#msg125075 date=1124821519]
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.
[/quote]

There must be some way the control tells you in what way it has stored the value.
August 27, 2005, 5:10 PM

Search