C++相談室 part85
■ このスレッドは過去ログ倉庫に格納されています
0689デフォルトの名無しさん
2010/10/30(土) 01:33:47要するにこういう感じで勝手にデストラクタが呼ばれるといけないわけだよね?
#include <iostream>
#include <boost/ptr_container/ptr_vector.hpp>
class Test {
int i;
public:
Test(int j) : i(j) {}
~Test() { std::cout << "~Test(" << i << ") is called" << std::endl; }
};
int main()
{
boost::ptr_vector<Test> ptt;
for (int i = 0; i < 10; i++)
ptt.push_back(new Test(i));
boost::ptr_vector<Test>().swap(ptt);
std::cout << "Excecution done" << std::endl;
}
~Test(0) is called
~Test(1) is called
~Test(2) is called
~Test(3) is called
~Test(4) is called
~Test(5) is called
~Test(6) is called
~Test(7) is called
~Test(8) is called
~Test(9) is called
Excecution done
■ このスレッドは過去ログ倉庫に格納されています