const 的重载
基于返回值是否是const 可以重载函数。 const 类对象成员。
const 对象只能使用const 成员。
类对保护成员的访问。
protected 不能被基类的对象访问,可以被基类的代码访问,派生类的代码可以访问基类的保护成员和自己的保护成员
例如:
void bulk_item::menfun(const bulk_item & temp, const item_base & tem)
{
// price is protected
sale_price=price; // ok sale_price = this->price;
sale_price=temp.price; // ok this class is bulk_item
sale_price=tem.price ; //error this class is item_base.
}
本文探讨了C++中const关键字的用法及其如何影响函数重载,并详细解释了类成员函数对于const对象的操作限制。此外,还介绍了protected成员的作用及访问规则,包括在派生类中的访问特性。
33万+

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



