16. The true form of the class

After continuous improvement, the structure struct becomes less and less like it looks in the c language,

Struct has its own meaning in C language and must continue to be compatible. In C++, a new keyword class is provided for class definition. The usage of class and struct is exactly the same.

What is the difference between class and struct?

    When defining a class with struct, the default access level of all members is public,

    When defining a class with class, the default access level for all members is private. .

Classes in C++ support separation of declaration and implementation: separate the implementation and definition of a class

 There are only class declarations in .h header files: declarations of member variables and member functions.

 Other implementations of the completion class in the .cpp source file: the concrete implementation of member functions.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325885781&siteId=291194637