lundi 7 septembre 2020

Destructor called twice with static object [duplicate]

test1.hpp

struct obj{
obj(){}
~obj(){cout<<"destroyed"<<endl;}
};
static obj x;

test1.cpp

#include "test1.hpp"

main.cpp

#include "test1.hpp"
int main(){...}

the destructor is getting called twice, why is this happening? gcc-7.5.0 os-ubuntu

Aucun commentaire:

Enregistrer un commentaire