名前空間の一部の const オブジェクトを初期化する際に問題が発生しています。次のような名前空間があります。
namespace myNamespace{
const std::string HI = "Hi";
const std::string BYE = "Bye";
inline std::vector<std::string> createHiAndByeVector(){
std::vector<std::string> temp;
temp.push_back(HI);
temp.push_back(BYE);
return temp;
}
const std::vector<std::string> HI_AND_BYE = createHiAndByeVector();
}
HI初期化をデバッグするとBYE、文字列リテラルが割り当てられていることがわかります。実行は initialziae まで続きHI_AND_BYEますが、関数に入ると、 と のcreateHiAndByeVector()両方HIにBYE値がなくなります。次に、push_back()メソッドでセグメンテーション違反が発生します。コール スタックを見ると、次の行が表示されます__static_initialization_and_destruction_0()。何が起こっている?オブジェクトが構築された直後に破棄されますか?