如:
CDialog* m_pages[20];
m_pages[0]=new CDialog1();
m_pages[1]=new CDialog2();然后判断m_pages[x]是哪个个类的实例,就是类似Java中instaneOf的方法谢谢
CDialog* m_pages[20];
m_pages[0]=new CDialog1();
m_pages[1]=new CDialog2();然后判断m_pages[x]是哪个个类的实例,就是类似Java中instaneOf的方法谢谢
MFC实现了一个简单的东西, IsKindOf,Baidu一下。
// compile with: /GR /EHsc
#include <iostream>typeid()
其实就是每个MFC对象声明的时候的DECLARE_DYNAMIC宏记录的继承信息。
我是要判断m_pages[x]是不是CDialog1(),而不是判断m_pages[x]是不是CDialog的派生类的对象...
m_pages[x]->IsKindOf(RUNTIME_CLASS(CDialog1))
to4楼,那我的类好多啊...有十几个...每个加个标识可以是可以就麻烦了点,有没有更好的方法呢我就是想知道m_pages[x]是CDialog1 还是 CDialog2
error C2039: 'classCDialog1' : is not a member of 'CDialog1'
要么就用typeid得到class name
我试过了,typeid(CDialog1).name() 返回的是CDialog不是CDialog1
AfxMessageBox(CString(typeid(a).name()));
建议LZ先上网搜一下IsKindOf/typeid的用法
CDialog1 a 这样写CString(typeid(a).name())得到的是CDialog1 如果是CDialog* m_pages[20];m_pages[0]=new CDialog1();这样写的话,得到的是CDialog
/*
To set this compiler option in the Visual Studio development environment
1. Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages. 2. Click the C/C++ folder. 3. Click the Language property page. 4. Modify the Enable Run-Time Type Info property.
*/CDialog* pDlg = new CDialog1;
AfxMessageBox(typeid(*pDlg).name());