Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you massively misread Stroustrup there, let me emphasise the part that I think is important:</p> <blockquote> <p>My rule of thumb is that you should have a <strong>real</strong> class <strong>with an interface and a hidden representation</strong> if and only if you can consider an invariant for the class.</p> </blockquote> <p>I believe he is specifically not talking about not using the <em>keyword <code>class</code></em> in this situation but is referring to a <em>logical class</em> (or "real class"). The difference is quite significant. A class <sup>(note the lack of markdown)</sup> is a data structure with a self contained interface and possibly a hidden implementation (see pimpl idiom). That means, the workings of a (logical) class are invisible to the user and a class object is communicated with via member functions and free functions. In terms of data abstraction that is sometimes interpreted as "don't access member variables from the outside" but that's just a shallower wording of the core idea.</p> <p>You should still use structured design for heterogeneous collections of data just as you do (or as <a href="https://stackoverflow.com/a/13326750/430766">Commander</a> or <a href="https://stackoverflow.com/a/13326796/430766">Dietmar Kühl</a> suggests). Whether or not you use the <code>class</code> or the <code>struct</code> keyword is personal taste, but I tend to use the <code>struct</code> keyword so it is clear that this type is <em>not</em> a class in the logical sense but just some data that belongs together. I find using a proper struct is preferable to an <code>std::tuple</code> as you can name all the members, giving them meaning, rather than accessing them by index and having to remember what every index was supposed to mean. In addition it is easier to modify and extend a <code>struct</code> in the future.</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