What are the differences between struct and class in C++?

后端 未结 30 3205
盖世英雄少女心
盖世英雄少女心 2020-11-21 05:38

This question was already asked in the context of C#/.Net.

Now I\'d like to learn the differences between a struct and a class in C++. Please discuss the technical d

30条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-21 05:57

    I found an other difference. if you do not define a constructor in a class, the compiler will define one. but in a struct if you do not define a constructor, the compiler do not define a constructor too. so in some cases that we really do not need a constructor, struct is a better choice (performance tip). and sorry for my bad English.

提交回复
热议问题