如果我在我的代码中像下面这样的类中使用静态数据成员,并声明该类的多个一个对象,那么哪个对象将销毁 静态数据成员 martians?
class martianGame
{
static int martians;
public:
martianGame();
static int getMartian();
};
martianGame::martians = 50;
int main()
{
martianGame game[10];
return 0;
}
最佳答案
how to destroy static data member in OOP?
静态数据成员,就像所有其他具有静态存储持续时间的对象一样,在程序结束时被销毁。因此,要销毁静态数据成员,您需要从 main
返回或调用 std::exit
。
which object will destroy the static data member martians?
没有对象。即使没有该类的实例,静态成员也会被构造和销毁。
关于c++ - 如何销毁 OOP 中的静态数据成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48480106/