exitするとローカル変数のデストラクタが呼ばれない話
#include <iostream> #include <string> class Test { public: Test(std::string str) : mStr(str) { std::cout << mStr << " create." << std::endl; } ~Test() { std::cout << mStr << " delete." << std::endl; } private: std::string mStr; }; Test test1("test1"); int main(void) { Test test2("test2"); exit(0); return 0; }
すると
test1 create.
test2 create.
test1 delete.
知らんかった……