i get confused in this part while we are using dynamic_cast to get ensure that the conversion result between pointers is valid complete object of the destination type , i can't get what is meaning by valid complete object here is example
#include <iostream>
#include <exception>
using namespace std;
class Base { virtual void dummy() {}
};
class Derived: public Base {public:
void print(){cout << "NiGHt!\n";
int a; };
int main () {
try {
Base * pba = new Derived;
Base * pbb = new Base;
Derived * pd;
pd = dynamic_cast<Derived*>(pba);
if (pd==0) cout << "Null pointer on first type-cast.\n";
pd = dynamic_cast<Derived*>(pbb);
if (pd==0) cout << "Null pointer on second type-cast.\n";
} catch (exception& e) {cout << "Exception: " << e.what();}
return 0;
}
if this two lines indicate that the conversion result succeed so why i can't use pointer pba to get into Derived class ?
pd = dynamic_cast<Derived*>(pba);
if (pd==0) cout << "Null pointer on first type-cast.\n";