09-01-2005
57,
0
Join Date: Aug 2005
Last Activity: 21 May 2010, 6:01 AM EDT
Posts: 57
Thanks Given: 0
Thanked 0 Times in 0 Posts
why to use dynamic cast in c++
class base
{
public:
virtual void disp()
{cout<<"from base\n";}
};
class derv : public base
{
public:
void disp()
{cout<<"from der\n";}
};
int main()
{
base *b=new derv;
b->disp();
derv *d;
d=dynamic_cast<derv*>(b);
d->disp();
return(0);
}
///using dynamic cast the derived type pointer can point base type pointer..why it is necessary...where we should suppose to use this/////
int main()
{
int i;
int j;
char *a="hi friend how are you";
i=reinterpret_cast<int>(a);
j=(int)a;
cout<<i<<endl;
cout<<j<<endl;
return(0);
}
both will give the same output..then what is the difference b/w reinterpret and ordinary c style cast.....in static_cast also same thing we use c style instead of static_cast....
Last edited by sarwan; 09-01-2005 at 06:48 AM..