在庫中使用一個符合標準的STL是否安全並且使用該庫的項目中使用另一個STL?例如:在封閉源代碼庫中使用STL
//library.h
#include <string> //let's say here it uses minGW STL
void Foo(std::string& str_mingw);
//library.cpp
void Foo(std::string& str_mingw) { /*do something*/ }
//application.cpp
#include "library.h"
#include <string> //let's say here it uses VStudio STL
void Bar()
{
std::string str_vstudio;
Foo(str_vstudio);
//Foo() inside the .lib or .dll uses string from minGW,
//but here a string from VStudio is used
}
在我看來,壞的事情會發生,尤其是如果用途是什麼不是簡單的字符串,但更復雜的像TR2 ::線程的東西。但是如果是這樣的話,我該如何在一個編譯器中編譯一個庫,並讓庫用戶自由地爲他們的項目選擇他們喜歡的編譯器?
Windows/MinWG n00b問:爲什麼不能在MinGW中使用VS STL? – Dummy00001 2010-08-31 14:01:48
標題不應該像「在單個項目中使用多個標準庫」一樣嗎?被閉源與被問到的實際問題似乎不相關。 – 2010-08-31 14:02:33
@Mark B 我指定了「閉源」,因爲客戶可以使用他們喜歡的任何STL來編譯開源庫,所以肯定沒有問題。 – user418680 2010-08-31 14:49:01