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

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

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

25条回答
  •  甜味超标
    2020-11-22 00:50

    Structs by default have public access and classes by default have private access.

    Personally I use structs for Data Transfer Objects or as Value Objects. When used as such I declare all members as const to prevent modification by other code.

提交回复
热议问题