您的位置:首页 > 编程语言 > C语言/C++

C++ self-learning notes(8)

2017-06-30 00:00 232 查看
摘要: class

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.



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

Example:



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

Results:



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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  class