Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Class methods are code. Code is constant. Each particular class method has a pre-determined fixed behavior defined at compile time that can't be changed at run time. For this reason, in order to have polymorphic classes, we have to write many different versions of different methods in advance (i.e. at compile time), and then "attach" a specific set of those versions to class instances at run time, thus forming the specific run time behavior of each instance.</p> <p>With data members the situation is completely different. Data members are not fixed. They are changeable. They hold values and these values can be freely changed at run time. This alone makes data members inherently "virtual" by themselves. You don't need to introduce an different "version" of data member in derived class. Instead, you just have to put a different value into an already existing data member. That alone is already analogous to the "virtuality" of the class methods. Moreover, this "data virtuality" is even more flexible than "virtuality" of the methods, because with data members you are not limited to a pre-determined set of values.</p> <p>What your are proposing though looks like a higher degree of "virtuality": not only the value of data member is changeable, but the data member itself is overridable. (Call it meta-virtuality, or super-virtuality or double-virtualty.) But what would be the point, the benefit, the use-case of having this feature? I personally don't see it right away and your code sample isn't exactly telling.</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