2014-03-27 38 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)

相關問題