2014-03-27 37 views
0

考虑以下代码将boost :: variant传递给(from)dll是否安全?

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; 
}; 

已知其通常为不安全的通STD通过动态库边界的对象。增强类型,特别是变体呢?

+0

同样的问题与提升与标准。总是依赖于编译器/编译器版本/升级版本。 – user1810087

+0

另外,在'variant'中有一个'std :: string':你觉得'variant'是多么神奇? – Yakk

回答

1

如果你能保证所涉及的所有模块共享相同的工具链/选项(即ABI),应该没有真正的麻烦[1]

不管这样的:

另外,如果你知道“等”模块是永远不会做的比商店以外的任何和传递引用返回给调用者的话,应该不会有什么问题或者。当你开始通过价值传递这些东西和/或在“外部”模块中间接引用/指针时,我会说你需要非常确定你的平台支持并测试它。


[1]以外不同的问题,如投掷跨越共享库边界/捕获异常的能力;这是相关的机器人不限于any(或一般RTTI)

相关问题