C++20 sections · 1024 units
Open in Course

When to Use Structs

Making the choice

Use structs when you have related data that belongs together. Coordinates, dates, RGB colors, student records. If you pass five parameters to every function, you probably need a struct.

Don't use structs for unrelated data. A struct with int age; string cityName; double temperature; makes no sense. Those aren't connected. Structs model entities. Start simple. Define a struct when you see the need.

When you catch yourself managing parallel arrays or long parameter lists, that's your signal.