Suppose I have:
class TypeA { };
class TypeB { };
typedef boost::variant<TypeA, TypeB> Type;
This is ok:
void foo(Type t) { }; int main(){ TypeA a; foo(a); }
This does not compile:
void foo(Type &t) { }; int main(){ TypeA a; foo(a); }
with the error:
invalid initialization of reference of type ‘Type&’ from expression of type ‘TypeA’
Also this does not compile:
void foo(Type *t) { }; int main(){ TypeA a; foo(&a); }
with the error:
cannot convert ‘TypeA*’ to ‘Type*’ for argument ‘1’ to ‘void foo(Type*)’
Is there a way to pass to a function that accepts a boost::variant an instance of one of the types aggregated by that boost::variant, either through a reference (as in case 2) or a pointer (as in case 3)?
Thank you very much!