How will you write your own dynamic cast which does the same work as the dynamic cast which C++ provides.
Coder 
Wednesday, July 07, 2010
class base { public : virtual der1* isDer1 () = 0 ; virtual der2* isDer2 () = 0 ; };
class der1 : public base { public : der1* isDer1 () { return this; } der2* isDer2 () { return 0; } };
class der2 : public base { public : der1* isDer1 () { return 0; } der2* isDer2 () { return this; } };
puneet 
Wednesday, July 07, 2010
Dynamica cast is for downcasting . I am not sure how Puneet's solution will work. I thought that something related to typeid would work.
Dyncamic cast will return NULL if I try to convert B* To D* if D is not derived from B.
Mahesh 
Wednesday, July 07, 2010
Agree that typeid is probably the only reasonable way to do this.
d 
Wednesday, July 07, 2010
D ; Can you give me an example to do that using typeid.
Coder 
Thursday, July 08, 2010
I thought typeid gave you access to the inheritance DAG, but it doesn't. You'd have to construct that out-of-band.
d 
Thursday, July 08, 2010
Can somebody come up with any kind of solution for this by writing a sample code
Coder 
Friday, July 09, 2010
|