博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ 纯虚函数
阅读量:4088 次
发布时间:2019-05-25

本文共 917 字,大约阅读时间需要 3 分钟。

15.6. Pure Virtual Functions

A pure virtual function is specified by writing = 0 after the function parameter list:

class Disc_item : public Item_base {

public:

double net_price(std::size_t) const =0;

};

Defining a virtual as pure indicates that the function provides an interface for sub-sequent types to override but that the version in this class will never be called. As importantly, users will not be able to create objects of type Disc_item.

 

An attempt to create an object of an abstract base class is a compile-time error:

// Disc_item declares pure virtual functions

Disc_item discounted; // error: can't define a Disc_item object

Bulk_item bulk; // ok: Disc_item subobject within Bulk_item

 

Note:A  class containing (or inheriting) one or more pure virtual functions is an  abstract base class  .  We may not create objects of an abstract type except as parts of objects of classes derived from the abstract base.

转载地址:http://myyii.baihongyu.com/

你可能感兴趣的文章
跳转到另一个页面之后取消后退按钮
查看>>
flutter踩坑高德地图amap_base
查看>>
flutter极光推送
查看>>
jvm崩溃并输出 hs_err_pidxxxx.log文件异常原因
查看>>
HXAPIGate(中文名:浩心API网关)
查看>>
Nginx搭建TCP反向代理服务
查看>>
netty整合shiro,报There is no session with id [xxxxxx]问题定位及解决
查看>>
Ignite配置
查看>>
Ignite计算网格第一部分
查看>>
将表单序列化之后变成的json格式的数据无法通过Ajax发送到后台的解决
查看>>
使用JAVA代码实现字符串的简单拼接
查看>>
java中的模版方法
查看>>
实现从oss(阿里云)服务器以附件形式下载文件(含批量下载)
查看>>
JSP页面以GET方式传参服务器报400
查看>>
自定义百度地图全局搜索结果的信息窗口
查看>>
SSM框架Jsp页面POST提交的中文数据保存到数据库变成乱码问题的分析
查看>>
j2ee编程实现将数据变成json格式的高效转换工具fastJson
查看>>
如何自己成功搭建一个SSM框架的WEB项目
查看>>
webservice知识一、SOAP风格的webservice——通过JDK的API发布一个webservice服务和创建一个webservice客户端用于访问该服务
查看>>
JavaEE开发之Spring中的多线程编程以及任务定时器详解(有源码)
查看>>