Class vs Struct for data only?

后端 未结 7 719
暖寄归人
暖寄归人 2020-11-28 15:35

Is there any advantage over using a class over a struct in cases such as these? (note: it will only hold variables, there will never be functions)

class Foo         


        
7条回答
  •  情深已故
    2020-11-28 16:32

    "(note: it will only hold variables, there will never be functions)"

    Never is a big word. Usually "never" means "eventually". Since that's the case, I'd suggest you use a class. That way, when things change, you don't have so much to change.

    The Java (and Python) folks have gotten along fine with everything being a class. It hasn't hurt them any to not have these specialized method-less classes that C++ calls a "struct".

提交回复
热议问题