EECS 231 FINAL NOTES

EECS 231 FINAL NOTES - EECS 231 FINAL NOTES VIRTUAL and...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
EECS 231 FINAL NOTES VIRTUAL and DERIVED FUNCTIONS C++ virtual function is a member function of a class, whose functionality can be over- ridden in its derived classes. The whole function body can be replaced with a new set of implementation in the derived class. The concept of c++ virtual functions is different from C++ Function overloading. C++ Virtual Function - Properties: C++ virtual function is, A member function of a class Declared with virtual keyword Usually has a different functionality in the derived class A function call is resolved at run-time The difference between a non-virtual c++ member function and a virtual member function is, the non-virtual member functions are resolved at compile time. This mechanism is called static binding. Where as the c++ virtual member functions are resolved during run-time. This mechanism is known as dynamic binding. C++ Virtual Function - Reasons: The most prominent reason why a C++ virtual function will be used is to have a different functionality in the derived class. For example a Create function in a class Window may have to create a window with white background. But a class called CommandButton derived or inherited from Window, may have to use a gray background and write a caption on the center. The Create function for CommandButton now should have a functionality different from the one at the class called Window. C++ Virtual function - Example:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

EECS 231 FINAL NOTES - EECS 231 FINAL NOTES VIRTUAL and...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online