ethz-asl / programming_guidelines

This repository contains style-guides, discussions, eclipse/emacs auto-formatter for commonly used programming languages
139 stars 38 forks source link

Use struct for classes without methods #7

Closed simonlynen closed 11 years ago

simonlynen commented 11 years ago

I don't agree with the wiki text: "Note that structs are kept in C++ for compatibility with C only, and avoiding them increases the readability of the code by reducing the number of constructs used. Use a class instead."

I would prefer using structs as pure data structs and classes in all other cases

stephanemagnenat commented 11 years ago

I second this, and even go further: struct are just classes with public members by default, there are use cases for which they make perfectly sense.

furgalep commented 11 years ago

I agree with Stephane. I like to use structs (with constructors) for simple POD types with no real methods.

stephanemagnenat commented 11 years ago

And this is likely to be increasingly useful in C++11 with the extension of the span of POD, the initializer list, and the {} syntax for initialising objects.