Friday, November 29, 2013

Virtual Keyword in C++

Simple Note

Use virtual keyword to define a function in a class that can be redefined in its derived class.

The only valid declaration (virtual or non-virtual) is the declaration within first level Class (first level here means the base class), redefine it in derived class will be ignored.

Also refer to http://ben-bai.blogspot.tw/2013/11/polymorphism-in-c.html

Tested with Dev-C++ 4.9.9.2

Program

https://github.com/benbai123/C_Cplusplus_Practice/blob/master/CPP/CPP_Basic/CPP_Extend_and_scope/virtual/virtual.cpp

Result


Reference

http://www.cplusplus.com/doc/tutorial/polymorphism/

No comments:

Post a Comment