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

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

    One other thing to note, if you updated a legacy app that had structs to use classes you might run into the following issue:

    Old code has structs, code was cleaned up and these changed to classes. A virtual function or two was then added to the new updated class.

    When virtual functions are in classes then internally the compiler will add extra pointer to the class data to point to the functions.

    How this would break old legacy code is if in the old code somewhere the struct was cleared using memfill to clear it all to zeros, this would stomp the extra pointer data as well.

提交回复
热议问题