C++ keyword using
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1896830/why-shall-i-use-the-using-keyword-to-access-my-base-class-method">Why shall I use the &ldquo;using&rdquo; keyword to access my base class method?</a>  </p>
</blockquote>



<p>Hi,</p>

<p>I can't find out why I needed the keyword <code>using</code> in the following case:</p>

<pre><code>// Pure virtual class.
class Visitor
{
  public:
      void operator()(Ast&amp;);

      virtual void operator()(Node&amp;) = 0;
};

// Define the default visit methods.
class DefaultVisitor : public Visitor
{
  public:
    using Visitor::operator();      // First 'using' needed.

    virtual void operator()(Node&amp;);
};

// A visitor using DefaultVisitor's behaviour.
class AVisitor : public DefaultVisitor
{
  public:
    using Visitor::operator();      // Second 'using' needed.

    virtual void operator()(Node&amp;);
};
</code></pre>

<p>Without the two <code>using</code> statements, the <strong>public</strong> non-virtual method declared and defined in <code>Visitor</code>, <code>void operator()(Ast&amp;);</code>, is not visible when called from <code>AVisitor</code>. For example:</p>

<pre><code>AVisitor v;
Ast* ast = new Node(); // Node is-a Ast
v(*ast); // should call Visitor::operator()(Ast&amp;);
</code></pre>

<p>will not compile, saying the method <code>void operator()(Ast&amp;)</code> does not match anything in AVisitor. The only solution is to use <code>using</code> keyword to import the abstract methods of the base class. But why ? Since it is public, I don't understand why this is needed.</p>

<p>Thank you.</p>
