class A 가 있을때
A* tmp = new A[100];
으로 만든 원소 A 100개는 delete [] tmp 하면 모두 destructor 가 불려지나요?
요컨대
delete [] tmp
for (int i = 0; i < 100; i++) tmp[i].~A(); delete [] tmp
직접 해보시면 금방 확인하실 수 있었을텐데요 ㅎㅎ
#include <iostream> class A { public: A() { std::cout << "Constructor" << std::endl; } ~A() { std::cout << "Destructor" << std::endl; } }; int main() { A* tmp = new A[3]; delete[] tmp; std::cout << "Hello World" << std::endl; return 0; }
Constructor Constructor Constructor Destructor Destructor Destructor Hello World
감사합니다.
Leo.
직접 해보시면 금방
직접 해보시면 금방 확인하실 수 있었을텐데요 ㅎㅎ
#include <iostream> class A { public: A() { std::cout << "Constructor" << std::endl; } ~A() { std::cout << "Destructor" << std::endl; } }; int main() { A* tmp = new A[3]; delete[] tmp; std::cout << "Hello World" << std::endl; return 0; }그렇군요.. ^^
감사합니다.
Leo.