33,321
社区成员




void listTest()
{
list<int*> lInt;
for (int i = 0; i < 1000; i++)
{
lInt.push_back(new int(i));
}
while (!lInt.empty())
{
int& m = *lInt.front();
std::cout << m << endl;
lInt.pop_front();
delete &m;
}
}
2: 在有new的地方马上放一个域守护
int* pi= new int();
SCP({delete pi;});
3: RAII
class PI
{
int* p;
PI() :p(new int()){};
~PI() {delete p;}
}