请帮忙,
问题:以下代码中的核心转储:
我有一个抽象类 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 之前被释放,但是有什么区别呢?当 main 已经完成时,两者都被释放。
您的帮助将不胜感激。