How do you type test in C++... Newb question :)

I

Irish

Hello all.... 1st post here

I was hoping someone could tell me how you test the datatype of a
variable in C++?
Like if I declare

struct ELEMENT{int key;} variable1;

OR

int variable2 = 10;

How can I type check variable1 or variable2?

I mostly write in Python... I'm looking for something similar to
python's way to do it... if there is in C++
type(variable1) #would return the datatype of variable1
or
isinstance(variable2, int) #would return true is variable2 is a
instance of the int class

Thanks in advance,
Chris
 
V

Victor Bazarov

Irish said:
Hello all.... 1st post here

Did you read the Welcome message? Did you read the FAQ? If you didn't,
please do. It is very important you have all the necessary information
about this newsgroup so we don't have to repeat ourselves.
I was hoping someone could tell me how you test the datatype of a
variable in C++?
Like if I declare

struct ELEMENT{int key;} variable1;

OR

int variable2 = 10;

How can I type check variable1 or variable2?

What do you mean? And what is it for?
I mostly write in Python... I'm looking for something similar to
python's way to do it... if there is in C++
type(variable1) #would return the datatype of variable1
or
isinstance(variable2, int) #would return true is variable2 is a
instance of the int class

No such thing exists in C++. What problem are you trying to solve by
using that approach? I am fairly certain there are other ways to solve
your problem.

V
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,211
Latest member
NelleWilde

Latest Threads

Top