Solved

# Virtual & Overide?

Posted on 2001-07-16

Now I know override will hide overload member functions in BASE class, there is a furture more question, what happened when I mark fun() as "virtual" like following,

This should generate a "VTBL" for BASE and Derived class but why the override sitll hides overloaded member functions in BASE class???

1 #include <stdio.h>

3

4 class BASE

5 {

6 public:

7 BASE() {};

8 ~BASE() {};

9 virtual fun() { cout << " BASE fun()" << endl; } ;

10 virtual fun(int ) { cout << " BASE fun(int)" << endl; } ;

11 virtual fun(int , int) { cout << " BASE fun(int )" << endl; } ;

12 };

13

14 class DERIVED: public BASE

15 {

16 public:

17 DERIVED() {};

18 ~DERIVED() {};

19 fun() { cout << " DETRIVED fun()" << endl; } ;

20 };

21

22

23 int main()

24 {

25 DERIVED *d1= new DERIVED();

26 BASE *d2= new DERIVED();

27

28 d1->fun(1); //Compile Error... Why??? fun is Virtual now

29

30 d2->fun(1); //OK

31 return 0;

32 }