C++ Object Oriented programming

本文探讨了C++中面向对象编程的三个核心方面:数据抽象、继承和动态绑定,并详细解析了多态性的概念及其实现方式。通过具体实例说明了如何在不同继承类型下访问基类成员,并介绍了柄类的概念及其在继承中的应用。

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

   Object Oriented programming is based on three fundamental conpects:data abstraction,inheritance,and dynamic binding.

   the key idea behind OOP is polymorphism. in C++,ploymorphism applies only to references or

pointers to types related  by inheritance.

   Dynamic binding lets us write programs that use objects of any type in an inheritance hierarchy without caring about the object's specific types.Programs that use these classes need not distinguish

between functions defined in the base or in a derived class.

   Protected Members,an important property: Aderived object may access the protected members of its base class only through a derived object.The derived class has no spicial access to the protected membes of base type objects.

  example:

 

Derived to Base Conversions

Because every derived object contains a base part,we can bind a base_type reference to the base-class part of a derived object. example:

Public,Private,and Protected Inheritance

   In Public inheritance,the members of the base retain their access levels.

   In Protected inheritance,the public and protected members of the base class are protected members

in the derived class.

   In private inheritance,all the members of the base are private in the derived class.

   All classes that inherit from base have the same access to the members in base,regardless of the access label in their derivation lists.the derivation access label controls the access that users of the derived class have to the members inherited from base.

 

a simple  example:

 

  

   Friendship and Inheritance

Frineds may access the class'private and protected data.

 

Handle Classes and Inheritance

   The handle class stores and manages a pointer to the base class.the type of the object to which that pointer points will vary,it can point at either a base-or a derived-type object.

Defining the handle

   In addition to managing the use count,the Sales_item class will define the dereference and arrow operators:

 

 

 

to be continue...

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值