Rookie foray into C + + (ii)--Classes and objects

Source: Internet
Author: User

Computer programming language involves a lot of data definition and data operation! To make them structured, modular, easy for users and programmers to understand and use, produced a class. Simply put, the class is like a computer host, looks neat and simple, but inside there are a variety of "hardware devices", the programmer through the external interface with the class to establish a connection, you can use the internal structure to complete their own tasks! Objects are modules that implement functionality specifically.


the composition of a class (yes?) )


A function is a function of the data through a certain operation, the class encapsulates the function together, you can implement a number of functions, through the interface call different functions to achieve different functions!

A class is the abstraction of a part of data that has the same characteristics! For example: dogs, cats, cows, etc. can be abstracted as animals, black cats, white cats can be abstracted as cats. From these two examples, it is not difficult to find that if you consider the properties of animals, the same point will be more universal, and the cat is more unique, the characteristics of more than animals! That is, the higher the class level, the fewer properties it has, the more common it is.

Class This "host" consists of data members and function members! To differentiate between private and public, C + + employs three types of data storage properties: Private,protect,public. Like computer software, some can change, some do not allow changes!

The class consists of data members and data functions! Some content is private, is not allowed to modify the user, like the computer's switch program, if modified, the computer will not be guaranteed to work properly! And we don't need to change it! And some of this is really modifiable! is called friend, it is estimated that in the event of an unexpected situation, by the professional and technical personnel to access it to find solutions to the problem!

The function of the interface is the public function defined by the Commons! All functions are defined by Class! Users see is left on the outside of the interface! If you want to use the module, connect to the class through the interface. Just like the keyboard connected to the host, only plug-in line can type the same!

There is also a protection level protect, which not only has the private access function for the class to use, but also can be called in subsequent subclasses of the inheritance.

Second, function module (how to do?) )

Objects need to pass through an interface to invoke these functions to implement functionality, in the following steps:

1. Define object, object reference function function.

2. function function Access constructor initialization.

3 function calculation, realize function output and function output.

4. All functions are executed, the destructor frees the memory, and the destructor outputs.

Summarize:

Class will function modular, with similar attributes of a set of data, the function is packaged to produce classes, only to understand the basic composition and implementation of the method, the C + + learning can be overview of the overall, macro control!

Rookie foray into C + + (ii)--Classes and objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.