What overheads and other considerations are there when using a struct vs a class?

As taken from the accepted answer from When should you use a class vs a struct in C++?

The only difference between a class and a struct in C++ is that structs have default public members and bases and classes have default private members and bases. Both classes and structs can have a mixture of public and private members, can use inheritance, and can have member functions.

I would recommend using structs as plain-old-data structures without any class-like features, and using classes as aggregate data structures with private data and member functions.

Memory wise the access modifier makes no difference and given the memory constraints of the Arduino, people are less likely to use classes with complex hierarchies, but prefer the POD structs anyway.


Unlike C, an instance of a struct in C++ is an object in exactly the same way as an instance of a class. From the point-of-view of the compiled code, they are identical. Memory usage, alignment, access times etc. are exactly the same (i.e. there are no overheads).

From the programmer's point-of-view, there is a very minor difference. Members of a struct have public visibility by default, whereas members of a class have private visibility by default. Otherwise, all language features work the same on both, such as constructors/destructors, inheritance, polymorphism, templates, and operator overloading. You can even derive a struct from a class, and vice versa.

Despite the similarity, it's quite common to see people deliberately using a struct in C++ for very simple structures, e.g. where it only consists of a few data members, but no functions. A class would be used for anything more complex. This is purely a matter of convention or personal preference though, and can be used as a subtle indication of the structure's intended complexity.


As other answers have pointed out, your particular struct and class are indistinguishable performance wise (There are slight differences in the scopes of the type names, due to the way you defined your struct). The delineation in C++ is not between struct and class, but between types that are POD (plain old data) and types that are not, as explained in this discussion.