Casting b/w Base Derived Class
Hi *!
Lets say i have a base class & derived classes like
PHP Code:
class main {
public:
virtual void foo(){}
};
class derive1 { void foo(){}};
class derive2 : public main, public derive1 { void foo(){}};
Now if i do something like that
PHP Code:
DWORD ret = (DWORD)static_cast<main*>((derive2*)1) - 1 ; // now ret = 0 O.K
ret = (DWORD)static_cast<derive1*>((derive2*)1) - 1 ; // now ret = 4 WHY????????? & HOW??????
What I dont understand is (it has to do something with virtual functions i think) But what exactly is it?????????
and secondly why am i getting 4 just by casting as far i understand casting is a hint that the var that is being casted to be treated of a different type then it is now after the cast but doenst have anything to do with the value.
Thanks for your time,
Regards,
Usman.