0

Consider this code

typedef boost::variant<int, std::string> var_t;

// this interface class will be implemented in DLL
class producer
{
public:
  virtual var_t produce() = 0;
};

// this class will be implemented by DLL user and 
// pointer to object of this class will be passed to producer
// as callback interface
class produce_handler
{
public:
  virtual void handle_produce(const var_t&) = 0;
};

It is known that it is generally unsafe to pass STD objects through dynamic library boundary. What about boost types, especially variant?

Alexander
  • 779
  • 8
  • 17

1 Answers1

1

If you can guarantee that all modules involved share the same toolchain/options (i.e. ABI), there should be no real trouble[1].

Regardless of this:

Also, if you know that the "other" module is never going to do anything other than store and pass a reference back to the caller, then there shouldn't be a problem either.

As soon as you start passing these things by value and/or indirecting the references/pointers in a "foreign" module I'd say you need to be very sure your platform supports this and test it.


[1] outside separate issues, such as the ability to throw/catch exceptions across shared library boundaries; this is related bot not confined to any (or RTTI in general)

sehe
  • 374,641
  • 47
  • 450
  • 633