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

被折叠的 条评论
为什么被折叠?



