您的位置:首页 > 编程语言 > C语言/C++

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

2015-03-26 16:18 281 查看
Question:

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

Answer:

The only difference between a class and a struct in C++ is that structs have default public members and bases and classes have default private members and bases. Both classes and structs can have a mixture of public and private members, can use inheritance,
and can have member functions.

I would recommend using structs as plain-old-data structures without any class-like features, and using classes as aggregate data structures with private data and member functions.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: