Pure Virtual Functions and Abstract Classes

Original Link:http://msdn.microsoft.com/en-us/library/aa273534(v=vs.60).aspx

C++ Specific —>

An abstract class contains at least one pure virtual function. Specify a virtual function as pure by placing = 0 at the end of its declaration. You don't have to supply a definition for a pure virtual function.

You cannot declare an instance of an abstract base class; you can use it only as a base class when declaring other classes.

END C++ Specific

Example

In the following program, draw() is a pure virtual function defined in the abstract class Shape. You cannot declare Shape objects. Shape acts as a base class for Rectangleand Circle. Rectangle and Circle provide definitions for draw(), so you can declare instances of those classes and call draw() for them.





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章