
Hello, I have a library with an abstract base class ABC and derived classes D1... Dn. These classes cannot be changed. User code wants to write code that depends on which concrete type the object being passed. User writes: void f( const ABC& abc ) { Tag t = abc.GetTag() ; // Tag is an enum for all the derived types, delivered by the lib Switch (t) { case: case: case: } } /// SO ugly, nevertheless if some case is missing, g++ for e.g. prints warnings I am told this is the visitor pattern I then looked at boost::variant<> The lib could deliver typedef boost::variant<D1, ... , Dn> ABCDerived; and the user could write visitors to visit ABCDerived objects, here the user is enforced to implement all cases in the visitor. but then the function f expects ABC objects. Can I still do: void f( const ABC& abc ) { // how to write code to use the visitors with abc ? } Rds,