Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dialog casting 1

Status
Not open for further replies.

Lorey

Programmer
Feb 16, 2003
88
SG
HI expeerts,

Just want to ask how to cast a dialog to a specific dialog class

i.e.

cdialog1(cdialog3);
cdialog1(cdialog2);

inside the cdialog, i want to know what kind of dialog is passed. i want to know if its a cdialog3 or cdialog2 so i can cast it to correct dialog class;
 
You need to switch on RTTI i.e. compile with /GR.

Once you have done that,
Code:
#include <typeid.h>
#include <cstring>
Where you need to do the check,
Code:
void CDialog1 (CDialog* xxx)
{
   if (strcmp (typeid (xxx).name (), "CDialog2*") == 0)
   ...
In the old wizard generated code, there used to be macros that got the name for you but this doesn't happen nowadays so you'll have to use the RTTI technique.

Another alternative is to dynamic_cast the item to whatever class you think it might be. If you get NULL, then try another class. Instead of comparing strings, you're just using the casting mechanism. You won't need to enable RTTI in this case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top