the reasons:

redriver (redriver)
1. In the definition of

14 class DETRIVED: public BASE
15 {
16 public:
17 DETRIVED() {};
18 ~DETRIVED() {};
19 fun() { cout << " DETRIVED fun()" << endl; } ;

firstly, the fun() is overided, so the fun(int) in BASE is not accessible in DETRIVED.
secondly, you use "25 DETRIVED *d1= new DETRIVED()", so d1 is pointer of object of DERIVED instead of BASE like d2.
2001-7-16 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: A question about C++ polymorphism & inheritence

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习English