C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

dynamic_cast

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Kapil Khosla
Guest





PostPosted: Sat Aug 23, 2003 8:20 am    Post subject: dynamic_cast Reply with quote



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





PostPosted: Sat Aug 23, 2003 2:49 pm    Post subject: Re: dynamic_cast Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.