A
asit
/*
* File: main.cpp
* Author: asit
*
* Created on 6 September, 2011, 7:08 PM
*/
#include <cstdlib>
#include <iostream>
using namespace std;
/*
*
*/
class A
{
public:
virtual void show()
{
cout<<"A"<<endl;
}
};
class B : public A
{
public:
void show()
{
cout<<"B"<<endl;
}
};
class C : public A
{
public:
void show()
{
cout<<"C"<<endl;
}
};
int main(int argc, char** argv)
{
B ob = new B;
void *ptr;
ptr = dynamic_cast<void*>(&ob);
B* pt2 = dynamic_cast<B*>(ptr);
return 0;
}
In the above code, why does the casting fails ??
* File: main.cpp
* Author: asit
*
* Created on 6 September, 2011, 7:08 PM
*/
#include <cstdlib>
#include <iostream>
using namespace std;
/*
*
*/
class A
{
public:
virtual void show()
{
cout<<"A"<<endl;
}
};
class B : public A
{
public:
void show()
{
cout<<"B"<<endl;
}
};
class C : public A
{
public:
void show()
{
cout<<"C"<<endl;
}
};
int main(int argc, char** argv)
{
B ob = new B;
void *ptr;
ptr = dynamic_cast<void*>(&ob);
B* pt2 = dynamic_cast<B*>(ptr);
return 0;
}
In the above code, why does the casting fails ??