助けてください、
問題: 次のコードのコア ダンプ:
抽象クラス SomeOtherClass があり、そこから SomeOtherClassImpl を派生させました。
問題を引き起こすコードは次のとおりです。
class MyClass
{
public:
void someFunction()
{
myVector().push_back(someOtherClassDefault());
}
private:
static std::vector<SomeOtherClass const *> & myVector()
{
static std::vector<SomeOtherClass const *> theVector;
return theVector;
}
static SomeOtherClass const * someOtherClassDefault()
{
static SomeOtherClassImpl theDefault;
return &theDefault;
}
};
他の翻訳単位に MyClass 型の静的変数がいくつかあります。
プログラムの終了時にセグメンテーション違反が発生するため、問題は奇妙です。もちろん、theDefault は theVector の前に割り当てを解除できますが、違いは何ですか? メインがすでに完了している場合、両方とも割り当て解除されます。
あなたが助けていただければ幸いです。