Should I use structs in C++?

Viewed 10246

The difference between struct and class is small in C++, basically only that struct members are per default public and class members are per default private.

However, I still use structs whenever I need pure data structures, for instance:

struct Rectangle {
    int width;
    int height;
};

I find that very convenient to work with:

Rectangle r;
r.width = 20;
r.height = 10;

However, data structures are from procedural programming, and I'm doing object oriented programming. Is it a bad idea to introduce this concept into OO?

10 Answers
Related