悪くないように見えるconst_stringlibを試していますが、実行時にアクセス違反(atomic_count、operator ++())でクラッシュします。テストコード:
#include <boost/const_string/const_string.hpp>
#include <boost/const_string/concatenation.hpp>
typedef boost::const_string<wchar_t> wcstring;
class Test
{
private:
const wcstring &s1;
const wcstring &s2;
public:
Test()
: s1(L"")
, s2(L"")
{
}
const wcstring &GetS1()
{
return s1;
}
const wcstring &GetS2()
{
return s2;
}
};
Test t;
int _tmain(int argc, _TCHAR* argv[])
{
//Test t;
wcstring t1 = t.GetS1(); // crashes here
wcstring t2 = t.GetS2();
return 0;
}
tがグローバルの場合にのみクラッシュします。宣言をmain()に移動すれば、問題ありません。システム:VS 2010、ブーストv。1.47.0
質問:私は何か間違ったことをしているのですか、それともライブラリ/コンパイラの問題ですか?誰かがC++用の不変文字列のより安定した実装を推奨できますか?