Does any one try the sample code on typeid, that post on MSDN(See
following)??
Seems it has something wrong to check with typeid operator,
the sample code is not going to work in my System...
cout << typeid( *pb ).name() << endl; //prints "class Derived"
this is the line causes exception....which is perfectly legal....
I have no idea why....
and its error message
First-chance exception at 0x77e4d756 in Test.exe: Microsoft C++ exception:
__non_rtti_object @ 0x0012fd78.
---------------------------------------
// expre_typeid_Operator.cpp
// compile with: /GR /EHsc
#include <iostream>
#include <typeinfo.h>
class Base {
public:
virtual void vvfunc() {}
};
class Derived : public Base {};
using namespace std;
int main()
{
Derived* pd = new Derived;
Base* pb = pd;
cout << typeid( pb ).name() << endl; //prints "class Base *"
cout << typeid( *pb ).name() << endl; //prints "class Derived"
cout << typeid( pd ).name() << endl; //prints "class Derived *"
cout << typeid( *pd ).name() << endl; //prints "class Derived"
delete pd;
}
--------------------------------------------------------------------
Full Error Messages
----------------------------------------------------------------------
'Test.exe': Loaded 'J:\CProject\Test\Debug\Test.exe', Symbols loaded.
'Test.exe': Loaded 'G:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'Test.exe': Loaded 'G:\WINDOWS\system32\kernel32.dll', No symbols loaded.
First-chance exception at 0x0046a7ce in Test.exe: 0xC0000005: Access
violation reading location 0x00000071.
First-chance exception at 0x77e4d756 in Test.exe: Microsoft C++ exception:
__non_rtti_object @ 0x0012fd8c.
Unhandled exception at 0x77e4d756 in Test.exe: Microsoft C++ exception:
__non_rtti_object @ 0x0012fd8c.