When should you use a class vs a struct in C++?

后端 未结 25 2346
误落风尘
误落风尘 2020-11-22 00:18

In what scenarios is it better to use a struct vs a class in C++?

25条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 01:03

    All class members are private by default and all struct members are public by default. Class has default private bases and Struct has default public bases. Struct in case of C cannot have member functions where as in case of C++ we can have member functions being added to the struct. Other than these differences, I don't find anything surprising about them.

提交回复
热议问题