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

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

    While implied by other answers, it's not explicitly mentioned - that structs are C compatible, depending on usage; classes are not.

    This means if you're writing a header that you want to be C compatible then you've no option other than struct (which in the C world can't have functions; but can have function pointers).

提交回复
热议问题