Possible Duplicate:
Why shall I use the “using” keyword to access my base class method?
Hi,
I can't find out why I needed the keyword using
in the following case:
// Pure virtual class.
class Visitor
{
public:
void operator()(Ast&);
virtual void operator()(Node&) = 0;
};
// Define the default visit methods.
class DefaultVisitor : public Visitor
{
public:
using Visitor::operator(); // First 'using' needed.
virtual void operator()(Node&);
};
// A visitor using DefaultVisitor's behaviour.
class AVisitor : public DefaultVisitor
{
public:
using Visitor::operator(); // Second 'using' needed.
virtual void operator()(Node&);
};
Without the two using
statements, the public non-virtual method declared and defined in Visitor
, void operator()(Ast&);
, is not visible when called from AVisitor
. For example:
AVisitor v;
Ast* ast = new Node(); // Node is-a Ast
v(*ast); // should call Visitor::operator()(Ast&);
will not compile, saying the method void operator()(Ast&)
does not match anything in AVisitor. The only solution is to use using
keyword to import the abstract methods of the base class. But why ? Since it is public, I don't understand why this is needed.
Thank you.