Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed introduction of objects and classes in C++

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "detailed introduction of objects and classes in C++". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Catalogue

What is the object?

Process oriented vs object oriented

Process oriented

object-oriented

What is a class?

The format of the class

Member functions of a class

Function access permission

Method one

Method two

Method three

Inline member function

What is the object?

Everything is an object, that is, everything in the legend is an object.

Composition of the object:

Data: describing the properties of an object

Function: code that describes the behavior of an object and operates accordingly according to external information

Objects with the same properties and behaviors are abstracted into class

A class is an abstraction of an object

Object is a special case of class.

Process-oriented vs object-oriented process-oriented

Process-oriented design:

Around the function, use a function to implement a function

Program = algorithm + data structure

The algorithm and the data structure are independent and designed separately.

object-oriented

Object-oriented design:

Encapsulate the algorithm and data in one object

Design the required singer classes and objects

Send a message to the object concerned

Object = algorithm + data structure

Program = object * n + message

What is a class?

In C++, classes are used to describe objects. The class belongs to the user-defined data type, and the data of this type has certain behavior ability, that is, the method described in the class. Generally speaking, the definition of a class consists of two parts, one is the properties of the class, the other is the methods owned by the class.

The format of the class

Format:

Class class name {public: / / Public behavior or attribute private: / / Private behavior or property}

Example:

Main.cpp:

# include "Student.h" using namespace std;int main () {Student student1 (1, "Little white",'f'); student1.display (); return 0;}

Student.cpp:

# include "Student.h" # include using namespace std;Student::Student (int n, string p, char g) {num = n; name = p; gender = g;} void Student::display () {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report