How much functionality is “acceptable” for a C++ struct?

后端 未结 19 2324
礼貌的吻别
礼貌的吻别 2021-02-07 09:31

My first post so please go easy on me!

I know that there\'s no real difference between structs and classes in C++, but a lot of people including me use a struct or class

19条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 09:55

    Consistency is most important. The point of conventions are to give a common point of reference for all those reading your code in the future.

    Personally, I avoid structs if I feel I need the functionality of a class.
    AKA: "plain old data" approach.

    Look at your project and set a standard, or adhere to the one already there.

    Though, I suggest you try to avoid inheritence, especially if all the struct is doing is holding POD. Nothing worse then tracing a bunch of super classes for an integer or char.

提交回复
热议问题