Код: Выделить всё
#include
#include
using namespace std;
struct S {
string name;
S(const string & n) : name(n) {
printf("%s(%s)\n", __func__, name.c_str());
}
~S() {
printf("%s(%s)\n", __func__, name.c_str());
}
void g() const {
printf("%s(%s)\n", __func__, name.c_str());
}
};
S f() {
return S("f");
}
S s("global");
int main(int argc, char ** argv) {
(void)argc, (void)argv;
printf("%s: begin\n", __func__);
for (int i=0; i
Подробнее здесь: [url]https://stackoverflow.com/questions/79311767/why-is-a-global-object-destructor-called-twice-after-initializing-a-reference-to[/url]