Generally, Private Members and objects cannot be accessed directly. They can only be accessed through the interface functions set in the class. Why is this setting required? It is very simple. For the sake of security, you can see the following code: # define deiostreamusingnamespacestd; classHuman {public: voidset (intw); intprint (); private: intweigh
Generally, Private Members and objects cannot be accessed directly. They can only be accessed through the interface functions set in the class. Why is this setting required? It is very simple. For the sake of security, you can see the following code: # include iostreamusing namespace std; class Human {public: void set (int w); int print (); private: int weigh
Generally, Private Members and objects cannot be accessed directly. They can only be accessed through the interface functions set in the class. Why is this setting required? It is very simple. For the sake of security, you can see the following code.
# Include
Using namespace std; class Human {public: void set (int w); int print (); private: int weight ;}; int main () {Human Tom; Tom. set (111); cout <"Tom's weight:" <
0 & w <100) {weight = w;} else {cout <"the output is out of the range. Set the default value to 0" <
The code is very clear, so that access through the interface will be safe. For example, when setting data, you can also set the conditions in the print interface, in this way, the program security will be very good.