Reputation: 1069
I have 2 structures Base and Derived and boost:variant with 2 types.
struct Base : public boost::static_visitor<>
{
virtual void operator(Type1& t) {}
virtual void operator(Type2& t) {}
};
What I want to do is do define Derived as:
struct Derived : public Base
{
void operator(Type1& t) { /*some impl*/ }
};
I do not override operator for the Type2 assuming it is defined in Base and empty.
For some reason if I write
Derived visitor;
boost::apply_visitor(visitor, variant);
I get error: no match for call to '(Derived) (Type2&)'
Of course, if I add operator for Type2 into derived it works ok.
Could anyone please help to understand why it is not working without adding operator for Type2?
Upvotes: 1
Views: 109
Reputation: 48968
Name lookup doesn't consider operators in base classes. You need to explicitly bring it in Derived
's scope for it to be seen by name lookup:
struct Derived : public Base
{
void operator()(Type1& t) { /*some impl*/ }
using Base::operator();
};
Upvotes: 3