Virtual Functions:
* If you need to modify behavior of a function in derived class then function should be defined as Virtual in base class.
* Virtual functions are especially useful to avoid Diamond problem
http://en.wikipedia.org/wiki/Virtual_functions
Pure Virtual Function:
Pure virtual functions are used by abstract classes. A class containing at least 1 pure virtual function is called abstract class. Pure virtual function is virtual function with empty body. Derived class has responsibility of implementing the function and not the base class. Base class in this case will be abstract class.
Example:
class AbstactClassname //This denotes the base class of C++ virtual function
{
public:
virtual void virtualfunctioname() = 0 //This denotes the pure virtual function in C++
};
Friday, November 12, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment