Hello All,
I was trying the below example for which I have a doubt. My doubt is
that why is virtual needed for function "dummy" in class CBase which
makes program compile?
Secondly, As per my current understanding of dynamic cast, pba is a
object of CDerived which RTTI knows and hence cast should be
successful. Isn't it? Which concept I didn't understand here ?
//Program to understand the dynamic cast.
#include <iostream>
#include <exception>
using namespace std;
class CBase
{
void dummy() {}
};
class CDerived: public CBase
{
};
int main () {
try {
CBase * pba = new CDerived;
CDerived * pd;
pd = dynamic_cast<CDerived*>(pba);
if (pd==0) cout << "Null pointer on first type-cast" << endl;
} catch (exception& e) {cout << "Exception: " << e.what();}
return 0;
}
Thanks.
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]