Classes and objects in C ++

Source: Internet
Author: User

C ++ is both an object-oriented and process-oriented language. Here is an important concept-class.

What is a class? Class is an abstraction of objects. For example, every real person is an object and has many common features (one head, two legs, walking, and running ), this person with common characteristics becomes a class. A class is an abstract term. Every person (I .e. an object) is an instance of this class.

The common characteristics of objects are the attributes and behaviors of objects. A video recorder is an object whose attributes are manufacturers, brands, weights, colors, and so on. Its behavior is its function, such as video recording, video recording, fast forward, and backward operations.

In the C ++ program, you must first define a class, such:

Class Name

{

Define variables;

....

Define functions

}

The member list in the class body, including data and operation data functions, that is, data members and member functions. This reflects the encapsulation of classes and the concealment of information.

Member functions are generally declared in the class body and defined in the class body.

Constructor: assign values to objects

Destructor: releases the space of the object member at the end of the function field.

Inline function: to save function call time

Complete various functions .......

To define an object, you need to instantiate the class. Shape: Class Name Object Name

A class is an abstraction that does not occupy any memory. It allocates space only when it is instantiated as an object.

Computers use objects to describe things in the world. Objects are connected by messages and functions are used to complete various functions.

In short, this is the object and class.

 

 

Related Article

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.