Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That is the way the language used to work. Prior to the <em>using</em> keyword, if you overrode one overloaded function, you had to overload them all:</p> <pre><code>class bar : public foo { public: bar(void); ~bar(void); a(int); a(double d) { foo::a(d); } // add this } </code></pre> <p>This annoyed enough people that the language committee added the <em>using</em> feature, but some old habits die hard; and the habitués&dagger; have a good argument.</p> <p>As James Hopkins points out, by adding <em>using</em>, the programmer is expressing the intention that the derived class will, without warning, add any future overrides of foo::a() to its list of acceptable signatures. </p> <p>Here is an example of what he describes:</p> <pre><code>#include &lt;iostream&gt; class Base { public: virtual void f(double){ std::cout &lt;&lt; "Base::Double!" &lt;&lt; std::endl; } // virtual void f(int) { std::cout &lt;&lt; "Base::Int!" &lt;&lt; std::endl; } // (1) virtual ~Base() {} }; class Derived : public Base { public: // using Base::f; // (2) void f(double) { std::cout &lt;&lt; "Derived::Double!" &lt;&lt; std::endl; } }; int main(int, char **) { Derived d; d.f(21); return 0; } </code></pre> <p>The output will be "Derived::Double!" because the compiler will promote the integer argument to a double. g++ 4.0.1 -Wall will not warn that this promotion occurred.</p> <p>Uncomment (1) to simulate a future change to Base adding the method Base::f(int). The code compiles, again without warning even with -Wall, and "Derived::Double!" remains the output.</p> <p>Now uncomment (2) to simulate a decision by the Derived programmer to include all Base::f signatures. The code compiles (without warnings), but the output is now "Base::Int!".</p> <p>&mdash;</p> <p>&dagger; I cannot think of an English word for "those who have the habit" and "addicted" is much too strong.</p>
    singulars
    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. 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.
 

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