Archived

This topic is now archived and is closed to further replies.

bilsa

dynamic_cast ?

Recommended Posts

bilsa    157
Hi, I''m having problem with a dynamic cast, which by my opinion should be succesfull:
class BaseC{
public:
	BaseC() {MessageBox(NULL,"BaseC Constructor", "Constructor", MB_OK);}
	virtual ~BaseC() {MessageBox(NULL,"BaseC Destructor", "Destructor", MB_OK);}
};

class DerivedC : public BaseC {
public:
	DerivedC():m_val("Works!") {MessageBox(NULL,"DerivedC Constructor", "Constructor", MB_OK);}
	virtual ~DerivedC() {MessageBox(NULL,"DerivedC Destructor", "Destructor", MB_OK);}
	void TestFunc() {MessageBox(NULL,m_val, "Constructor", MB_OK);}
private:
	char* m_val;
};

//then:


	 BaseC *baseObject = new DerivedC();

	 DerivedC *derivedObject = dynamic_cast<DerivedC*>(baseObject);
	 
	 if(derivedObject != NULL) {
		derivedObject->TestFunc();
	 }
This gives me a RunTime error on the dynamic_cast. But from what I have read it is supposed to work like this?? thx!

Share this post


Link to post
Share on other sites
bilsa    157
"Microsoft Visual C++ Runtime Library"
"
Runtime Error!

Program: ...

This application has requested the Runtime to terminate it in an unusual way.
Please contact the applications support team for more information."

I''m using VC++ .NET 2003
WinXP

Share this post


Link to post
Share on other sites
Kumppi    122
Have you enabled runtime type info on your compiler? At least in VC++.NET 2002 RTTI is not enabled on default.

"Life is very short, and there''s no time for fussing and fighting my friend..."

Share this post


Link to post
Share on other sites