If all the types in my boost::variant
support the same method, is there a way to call it generically (i.e. not calling it seperately for each method of the static_visitor
)?
I'm trying to get something like this to work:
class A
{
void boo() {}
};
class B
{
void boo() {}
};
class C
{
void boo() {}
};
typedef boost::variant<A, B, C> X;
void foo(X& d)
{
x.boo();
}
but it fails to compile saying 'boo' : is not a member of 'boost::variant<T0_,T1,T2>'
.
Currently, I have some classes all inherit from an interface so that their single shared method can be used polymorphically. I also want to be able to use the classes via a visitor as all other methods are unique to each concrete class. I was hoping boost::variant
might be a better alternative to implementing my own visitor mechanism here. Is it?