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

后端 未结 30 3732
盖世英雄少女心
盖世英雄少女心 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:56

    The other answers have mentioned the private/public defaults, (but note that a struct is a class is a struct; they are not two different items, just two ways of defining the same item).

    What might be interesting to note (particularly since the asker is likely to be using MSVC++ since he mentions "unmanaged" C++) is that Visual C++ complains under certain circumstances if a class is declared with class and then defined with struct (or possibly the other way round), although the standard says that is perfectly legal.

提交回复
热议问题