 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kapil Khosla Guest
|
Posted: Sat Aug 23, 2003 8:20 am Post subject: dynamic_cast |
|
|
Hi,
I have a small code in which I am playing with dynamic_cast. It gives
me a runtime exception and says unhandled exception in kernel32.dll ,
non rtti object.
Kapil
class BaseClass
{
public:
virtual void f(void) const {cout <<"Basen";}
};
class DerivedClass : public BaseClass
{
public:
void f(void) const { cout << "Derivedn"; }
};
void test(BaseClass *);
int main()
{
BaseClass base;
DerivedClass derived;
test(&base);
test(&derived);
cin.get();
return 0;
}
void test(BaseClass *basePtr)
{
if(dynamic_cast
cout << " Derived Class Object" << endl;
}
// It works if I change DerivedClass to BaseClass
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Maciej Sobczak Guest
|
Posted: Sat Aug 23, 2003 2:49 pm Post subject: Re: dynamic_cast |
|
|
Hi,
Kapil Khosla wrote:
| Quote: | I have a small code in which I am playing with dynamic_cast. It gives
me a runtime exception and says unhandled exception in kernel32.dll ,
non rtti object.
|
In some compilers, RTTI is not enabled by default.
Try to find appropriate compiler switch (or the option in project
settings) so that RTTI is enabled.
The code itself looks OK and works fine on g++ 3.2.
--
Maciej Sobczak
http://www.maciejsobczak.com/
Distributed programming lib for C, C++, Python & Tcl:
http://www.maciejsobczak.com/prog/yami/
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|