What is the encapsulation method of C++
This article introduces the relevant knowledge of "what is the encapsulation method of 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!
Encapsulation
C++ believes that everything is an object, and the object has its attributes and behavior.
The meaning of encapsulation:
Attribute and behavior as a whole to express things in life
Apply permission control to attributes and behaviors
Encapsulation meaning one:
When designing a class, properties and behaviors are written together to represent things
Syntax:
Class class name {access rights: attribute / behavior}
Attributes and behaviors as a whole # includeusing namespace std;// pi const double PI = 3.14 / designing a circle class to find the perimeter of the circle / / the formula for finding the perimeter of the circle: 2circle Pi * radius class Circle {/ / access rights / / common permissions public: / / attributes / / radius int masks r / / behavior / / get the perimeter of a circle double calculateZC () {return 2 * PI * m circle;}}; int main () {/ / create a concrete circle (object) through a circle class / / instantiate (the process of creating an object through a class) Circle C1 / / assign a value to the attributes of the circle object c1.m_r = 10; / / 2 * PI * m _ r = 62.8; cout