C++: When should I use structs instead of classes and where are the speed differences?

前端 未结 5 716
别跟我提以往
别跟我提以往 2021-02-02 10:42
  • When should I use a struct instead of a class? I\'m currently using classes for everything from OpenGL texture wrappers to bitmap fonts.

  • Is

5条回答
  •  孤街浪徒
    2021-02-02 11:19

    Structs and classes in C++ as you may know differ solely by their default access level (and default accessibility of their bases: public for struct, private for class).

    Some developers, including myself prefer to use structs for POD-types, that is, with C-style structs, with no virtual functions, bases etc. Structs should not have behavior - they are just a comglomerate of data put into one object.

    But that is naturally a matter of style, and obviously neither is slower

提交回复
热议问题