Nonvirtual Calls Are Resolved at Compile Time【c++ primer】

本文探讨了在C++中非虚函数如何基于对象引用的类型在编译时期被解析,即使实际对象类型不同,非虚函数调用也总是指向基类的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Regardless of the actual type of the argument passed to print_total , the call of book is resolved at

compile time to Item_base::book .

Even if Bulk_item defined its own version of the book function, this call

would call the one from the base class.


Nonvirtual functions are always resolved at compile time based on the type of the object, reference, or pointer from which the function is called. The type of item is reference to const Item_base , so a call to a nonvirtual function on that object will call the one from Item_base regardless of the type of the actual object to which item refers at run time.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值