Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>MyClass</code>, from a compiler's perspective, is a way to omit a <code>callvirt</code> instruction in favor of a <code>call</code> instruction. Essentially when you call a method with the virtual semantics (<code>callvirt</code>), you're indicating that you want to use the most derived variation. In cases where you wish to omit the derived variations you utilize <code>MyClass</code> (<code>call</code>). While you've stated you understand the basic concept, I figured it might help to describe it from a functional viewpoint, rather than an implicit understanding. It's functionally identical to <code>MyBase</code> with the caveat of scope being base type with <code>MyBase</code>, instead of the active type with <code>MyClass</code>.</p> <p>Overriding virtual call semantics, at the current point in the hierarchy, is typically a bad design choice, the only times it is valid is when you must rely on a specific piece of functionality within your object's hierarchy, and can't rely on the inheritor to call your variation through a base invocation in their implementation. It could also rely on you as a designer deciding that it's the only alternative since you overrode the functionality further in the object hierarchy and you must ensure that in this corner case that this specific method, at the current level of the inheritance tree, must be called.</p> <p>It's all about design, understanding the overall design and corner cases. There's likely a reason C&#9839; doesn't include such functionality since on those corner cases you could separate the method into a private variation the current level in the hierarchy invokes, and just refer to that private implementation when necessary. It's my personal view that utilizing the segmentation approach is the ideal means to an end since it's explicit about your design choice, and is easier to follow (and it's also the only <em>valid</em> means in languages without a functional equivalent to <code>MyClass</code>.)</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