473,666 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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(vari able2, int) #would return true is variable2 is a
instance of the int class

Thanks in advance,
Chris

Nov 3 '05 #1
2 2254
Irish wrote:
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(vari able2, 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
Nov 3 '05 #2
Thanks for the info Victor. I found a fix for my problem :)

Nov 3 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1637
by: David E. | last post by:
So as a programmer, what's the best thing to study? EJB? How much of the J2EE or Enterprise architecture is necessary to no? I guess I need a good overview for a newb like me... thanks.. -- N0 Spam Ema|l address. Please, when replying directly, delete "NSPAMO" from email address. Thanks
1
1549
by: notbob | last post by:
Newb here! Using 4.0.20 on Slack. Slogging through the official manual. At 2.4.3 Securing the Initial MySQL Accounts, I'm finally stopped cold while trying to follow instructions. Here's what I did: shell> mysql -u root mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd'); .....as per instructed (I just cut 'n paste). I then quit mysql and log back on as root:
4
1436
by: Donald Newcomb | last post by:
I'm a real Python NEWB and am intrigued by some of Python's features, so I'm starting to write code to do some things to see how it works. So far I really like the lists and dictionaries since I learned to love content addressability in MATLAB. I was wondering it there's a simple routine (I think I can write a recurisve routine to do this.) to scan all the elements of a list, descending to lowest level and change something. What I'd like...
6
1676
by: Sean Berry | last post by:
Hello all I have build a list that contains data in the form below -- simplified for question -- myList = ,, ...] I have a function which takes value3 from the lists above and returns another value. I want to use this returned value to sort the lists. So, my resultant list would be ordered by the return value of the
11
1988
by: The_Kingpin | last post by:
Hi all, I'm new to C programming and looking for some help. I have a homework project to do and could use every tips, advises, code sample and references I can get. Here's what I need to do. I have a file named books.txt that contains all the informations on the books. Each book is a struc containing 6 fields written on separated line in the
2
1183
by: Benign Vanilla | last post by:
I created a web site in ASP that is heavily data driven. On the home page, http://iheartmypond.com/. The list of categories is gathered from the database. I grab the distinct top level categories, and show them with the first five level 1 sub categories. I then loop through the list and using response.write, I build a table that formats the category lists as shown on the home page. I am trying to replicate this in ASPX and having all...
4
4221
by: sklett | last post by:
I'm revisiting an old series of overloaded methods I have and I would like to convert them to a single generic method. Here is the method in it's current, overloaded implementation: <code> public StringCustomFieldRef GetStringField(string fieldID, CustomRecord record) { if(record.customFieldList == null) { return null;
6
1637
by: cppnow | last post by:
Hello. I have a strange conceptual problem I'm trying to think about. I would like to build a library that allows the user to do the following: 1) User defined types: The user defines their own types as needed for their particular application and registers them with the library. class ClassA {};
5
1454
by: Fredo | last post by:
I'm new to Generics (years and years of VS.NET 2003 development, but very little .NET 2.0+). I have some routines for conversion from RGB to different color spaces and back. I would like the routines to support, at least, byte, int, and double types without having to create different versions of the routines. Is there any way to do this with generics? The problem is, if I do something like this: public static void RGB_to_YIQ<T>(T R, T...
0
8445
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.