Wave的专栏

共享与提高-----点滴积累;积跬步,至千里

What is a pure virtual function?

What is a pure virtual function?

A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be "pure" using the curious "=0" syntax. For example:

 Here, Base is an abstract class (because it has a pure virtual function), so no objects of class Base can be directly created: Base is (explicitly) meant to be a base class. For example: 

 Abstract classes are immensely useful for defining interfaces. In fact, a class with only pure virtual functions is often called an interface. 

You can define a pure virtual function:


 This is very occasionally useful (to provide some simple common implementation detail for derived classes), but Base::f3() must still be overridden in some derived class. 

If you don't override a pure virtual function in a derived class, that derived class becomes abstract:


 
转载自:http://www.research.att.com/~bs/bs_faq2.html#pure-virtual
                之 
Bjarne Stroustrup's C++ Style and Technique FAQ
阅读更多
文章标签: class function c++
个人分类: C/C++
想对作者说点什么? 我来说一句

R6025 pure virtual function call

2010年04月13日 4.51MB 下载

没有更多推荐了,返回首页

不良信息举报

What is a pure virtual function?

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭