473,480 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to know the type of variable at run time??

6 New Member
Hi All,

I am using VC++ MFC Application.

I want to know the typeof my variable at run time, how can I do that? I hope it is possible with the typeof operator, but it gives me error like this identifier not found.So, is it possible with VC++ to use something like typeof operator??

Thanks in Advance.



Ashish
Oct 24 '07 #1
3 15653
gpraghuram
1,275 Recognized Expert Top Contributor
Hi All,

I am using VC++ MFC Application.

I want to know the typeof my variable at run time, how can I do that? I hope it is possible with the typeof operator, but it gives me error like this identifier not found.So, is it possible with VC++ to use something like typeof operator??

Thanks in Advance.



Ashish
In c++ u can do this using typeid.
Check this link for more info on it

Raghuram
Oct 24 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
I want to know the typeof my variable at run time,
How did you get in this pickle? Usually in C++ if you need to know the type of the object your design is faulty.

Besides, the typeid operator only works if your class has virtual methods. The reason is that the derived object may be known only by a base class pointer.

If your class does ot have virtual methods, then you already know the type.
Oct 24 '07 #3
use dynamic_cast...
Expand|Select|Wrap|Line Numbers
  1. if (dynamic_cast<type>(var))
  2. {
  3.   // 'var' is an instance of 'type'
  4. }
Oct 7 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
41021
by: jb | last post by:
Hello, I need to know which button was pressed in the submit , i tried reading the vaule of submit it the validateDate function but it returns 'undefined' value ; I do this in asp all the time, Not...
10
1580
by: Eitan | last post by:
Hello, I want to know, wheter an asp (that call itself in "get" method, has passed any parameter to itself). i.e : in the asp : test_asp.asp : ..... <html> <body>
3
2096
by: Vinodh Kumar P | last post by:
Whenever I read any C++ literature I find the words "C++ is statically type checked".OK.Agreed. Is there any language that supports "Dynamic type checking"? In such a case any type can be assigned...
14
2513
by: sathya_me | last post by:
Dear clc, I have a variable void *a; Since variable "a" can be assigned (point to) any type and also any type can be assigned to "a" (i.e means "a" = any typed variable; any typed variable =...
51
4446
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
8
1333
by: Leszek Taratuta | last post by:
Hello, I have the following code: // Load the MenuBar.ascx user control. The control defines SavePropertyEvent event. UserControl ctrl =...
3
3176
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
6
5969
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The...
10
1862
by: marc | last post by:
Hoi there, I am a Delphi Programer who moved over to C# some months ago. So far I am really happy with C# and feelt myself confortable quite fast. Just some advanced questions regarding the type...
9
1863
by: Coleen | last post by:
Hi All :-) I am desperately looking for some help/information on how to direct page flow. Forget what I have done - here's what I need to do: I have a large ASPX.Net - VB.Net web application...
0
7052
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,...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6981
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...
0
5348
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,...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3000
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...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.