Get the App
SLTechnology News&Howtos  ›  Development  › 

C++ object Model and how to use this pointers

Shulou Source: shulou.com Published: 2022-05-31 19:51:16 09月12日 Update

Most people do not understand the knowledge points of this article, "C++ object model and how to use this pointers", so the editor gave you a summary of the following contents, detailed contents, clear steps, and a certain reference value. I hope you can get something after reading this article. Let's take a look at this "C++ object model and how to use this pointers" article.

The three object-oriented features of C++ are encapsulation, inheritance and polymorphism.

C++ believes that everything is an object, and the object has its attributes and behavior.

For example:

People can be used as objects, with attributes such as name, age, height, weight. Behaviors include walking, running, jumping, eating, singing.

The car can also be used as an object, with properties such as tires, steering wheel, headlights. The behaviors include carrying people, playing music and playing air conditioners.

Objects with the same nature can be abstractly called classes. People belong to human beings and cars belong to cars.

C++ object model and this pointer 1 member variables and member functions are stored separately

In C++, member variables and member functions within a class are stored separately

Empty object occupies one byte

The C++ compiler allocates a byte of space to each empty object to distinguish where the empty object occupies memory.

Each empty object should also have a unique memory address.

Non-static member variables, on objects belonging to the class

Static member variables, on objects that do not belong to the class

Non-static member function, on an object that does not belong to the class

Static member function, on an object that does not belong to the class

Non-static member variables, on objects belonging to the class, why?

The empty object originally occupies 1 byte, but after adding the non-static member variable [int], it takes up 4 bytes.

Summary: only non-static member variables belong to the object of the class.

Class Person {public: Person () {mA = 0;} / / non-static member variables occupy object space int mA; / / static member variables do not occupy object space static int mB; / / functions do not occupy object space, and all functions share a function instance void func () {cout

Tags: Objects members functions pointers variables static centering pointing properties space content model bytes code memory behavior formal parameters storage special key Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux Shulou Technology OPPO Reno Huawei