C++ self-learning notes(8)

class

In C++, class can be seen as an upgrade version of struct in C.  In a class, there can be variables, constants and functions which can be divided into three sections: private, protected and public. Parent classes can derive son classes and son classes can inherit certain characters from their parents. 

The variables defined by a class is called an object. C++ sometimes referred to as the "Object Oriented Programming " language (OOP). Here is a flow chart below shows the difference between C & C++ and how is C++ orienting to Objects.

122208_DwES_2968040.png

And here is an example shows how to work with classes in C++ below.

Example:

152700_unv9_2968040.png

Notice: in the code, the class pointer was deleted. Remembering deleting the useless objects in your codes is a good habit for programming.

Results:

122425_QYfb_2968040.png

As you can see in the class <angl>, I defined two construction functions. The default construction function is the empty function: angl(){} which is used to initialize the object we defined afterwards in the main function. To find out more about initializing, please find the  following website: http://c.biancheng.net/cpp/biancheng/view/2979.html 

Moreover, if we use the keyword "typedef" on the class <angl>, it will help us to use the class more conveniently.

The "wrapping" by classes makes the construction of projects much easier. However, the OOP style does not improve the efficiency of the codes. This programming maner was created just to make it easier for programmer to order their codes. 

In a real coding case, people usually decare functions in the header and specify the function in the source file. 

 

Useful Links:

http://c.biancheng.net/cpp/biancheng/view/2968.html

http://www.cnblogs.com/mr-wid/archive/2013/02/18/2916309.html

转载于:https://my.oschina.net/u/2968040/blog/1083213

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值