c**********e 发帖数: 2007 | 1 Is there anything wrong with the following code?
class A {};
class B : public A {};
void main() {
A* a;
B* b=a;
} |
m********l 发帖数: 4394 | 2 what's not wrong about the code?
------------
actually, in c# it's definitely wrong.
How about C++?
does the RTTI check it?
【在 c**********e 的大作中提到】 : Is there anything wrong with the following code? : class A {}; : class B : public A {}; : void main() { : A* a; : B* b=a; : }
|
l*****a 发帖数: 14598 | 3 obviously, base class pointer is not a derive class pointer
here u need type conversion
B* b=dynamic_casta;
【在 c**********e 的大作中提到】 : Is there anything wrong with the following code? : class A {}; : class B : public A {}; : void main() { : A* a; : B* b=a; : }
|