博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ 编译时期的名字查找
阅读量:4089 次
发布时间:2019-05-25

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

15.5.1. Name Lookup Happens at CompileTime

The static type of an object, reference, or pointer determinesthe actions that the object can perform. Even whenthe static and dynamic types might differ, as can happen when a reference orpointer to a base type is used, the static type determines what members can beused. As an example, we might add a member to the Disc_item class that returns a pair holding the minimum (or maximum) quantity and the discounted price:

 

class Disc_item : public Item_base {

public:

std::pair<size_t, double>discount_policy() const

{ return std::make_pair(quantity,discount); }

// other members as before

};

 

Wecan access discount_policyonly through an object, pointer, or reference of typeDisc_item or a class derived from Disc_item:

 

Bulk_item bulk;

Bulk_item *bulkP = &bulk; // ok:static and dynamic types are the same

Item_base *itemP = &bulk; // ok:static and dynamic types differ

bulkP->discount_policy(); // ok:bulkP has type Bulk_item*

itemP->discount_policy(); // error:itemP has type Item_base*

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

你可能感兴趣的文章
(五)pdf的构成之文件体(catalog对象)
查看>>
[BUG]自己的bug自己解,记一次在变量使用过程引发的bug
查看>>
vue通过Blob实现下载文件
查看>>
青柠开车Spring Cloud(二) —— 准备工作与开发环境
查看>>
Swift实战-小QQ(第2章):QQ侧滑菜单
查看>>
为什么HashSet里value不是null?
查看>>
Eclipse中的Debug
查看>>
史上最简单的 SpringCloud 教程
查看>>
Guava学习
查看>>
调用函数时参数传递的单向性分析
查看>>
(五)ELK Logstash output
查看>>
js获取网页屏幕可见区域高度
查看>>
Centos7.5安装VirtualBox-5.2
查看>>
Extjs editor plugins
查看>>
Java List操作
查看>>
day16 常用模块 sys os json pickle
查看>>
Docker国内镜像source
查看>>
html——特例
查看>>
python-全局替换程序
查看>>
javax.management.InstanceNotFoundException: com.alibaba.druid:type=DruidDataSourceStat解决方案
查看>>