Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found one mechanism, where at least we are prompted to announce the overridden method <em>explicitly</em>. It's not the perfect way, but at least somewhat near.</p> <p>Suppose, we have few pure <code>virtual</code> methods in <code>class B</code> (base):</p> <pre><code>class B { virtual void foo () = 0; virtual void bar (int) = 0; }; </code></pre> <p>Among them, I want <code>foo()</code> to be overridden by the whole hierarchy, then abstract <code>foo()</code> 1 level up for simplicity:</p> <pre><code>class Register_foo { template&lt;typename T&gt; // this matches the signature of 'foo' Register_foo (void (T::*)()) {} }; class Base : public virtual Register_foo { // &lt;---- virtual inheritance virtual void bar (int) = 0; Base () : Register_foo(&amp;Base::foo) {} // &lt;--- explicitly pass the function name }; </code></pre> <p>Every subsequent child class in the hierarchy would have to <em>register</em> its <code>foo</code> inside its <em>every constructor</em> <strong>explicitly</strong>. e.g.:</p> <pre><code>struct D : B { D () : Register_foo(&amp;D::foo) {} D (const D &amp;other) : Register_foo(&amp;D::foo) {} virtual void foo () {}; }; </code></pre> <p>This registration mechanism has nothing to do with the business logic. But at least inside the constructor of any child class it would be mentioned that, which <code>foo</code> it's using.<br> Though, the child <code>class</code> can choose to register using its own <code>foo</code> or its parent's <code>foo</code>, but at least that is <em>announced</em> explicitly. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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