C++ struct, public data members and inheritance
- by Marius
Is it ok to have public data members in a C++ class/struct in certain particular situations?
How would that go along with inheritance?
I've read opinions on the matter, some stated already here
http://stackoverflow.com/questions/952907/practices-on-when-to-implement-accessors-on-private-member-variables-rather-than
http://stackoverflow.com/questions/670958/accessors-vs-public-members
or in books/articles (Stroustrup, Meyers) but I'm still a little bit in the shade.
I have some configuration blocks that I read from a file (integers, bools, floats) and
I need to place them into a structure for later use. I don't want to expose these externally just use them inside another class (I actually do want to pass these config parameters to another class but don't want to expose them through a public API).
The fact is that I have many such config parameters (15 or so) and writing getters and setters seems an unnecessary overhead. Also I have more than one configuration block and these are sharing some of the parameters. Making a struct with all the data members public and then subclassing does not feel right. What's the best way to tackle that situation?
Does making a big struct to cover all parameters provide an acceptable compromise (I
would have to leave some of these set to their default values for blocks that do not use them)?