Thursday, November 18, 2010

virtual function and pure virtual function

If a function has a key word "virtual", that's a virtual function. If the whole virtual function equals to zero, that's pure virtual function.
For example, virtual void f(int)-----------------------------normal virtual function, non-pure virtual function
                     virtual void f(int)=0--------------------------pure virtual function
If it's a pure virtual function, the base function cannot be implemented, but the derived functions must be implemented.
If it's a normal virtual function, that means it is not a pure virtual function, the derived functions may be implemented or may not be implemented. Therefore, the base functions must be implemented.(I guess. Depends on different compilers, it may give you an error message.) 

1 comment:

  1. Thanks Chen! Nice and brief explanation...good one here too: Pure virtual function example

    ReplyDelete