C++ classes and objects, private cannot be called by other classes

Insert picture description here
Person class is substantiated into p object (object is the substantive of class, person class is equivalent to int class), which is defined in private and can only be used in p (that is, person class)

_name is private, so it cannot be used outside the person class (main class), and other classes (not main) can appear p._age or pso->g_best
if they are not hungry , while _age, Eat() are public, so in Outside the class (main class) can be used directly

Guess you like

Origin blog.csdn.net/qq_43641765/article/details/110009294