Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ struct, public data members and inheritance
    text
    copied!<p>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</p> <p><a href="https://stackoverflow.com/questions/952907/practices-on-when-to-implement-accessors-on-private-member-variables-rather-than">practices on when to implement accessors on private member variables rather than making them public</a> <a href="https://stackoverflow.com/questions/670958/accessors-vs-public-members">Accessors vs. public members</a></p> <p>or in books/articles (Stroustrup, Meyers) but I'm still a little bit in the shade.</p> <p>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). </p> <p>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)?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload