看看这段代码:
class test
{
public:
test() { cout << "Constructor" << endl; };
virtual ~test() { cout << "Destructor" << endl; };
};
int main(int argc, char* argv[])
{
test* t = new test();
delete(t);
list<test*> l;
l.push_back(DNEW test());
cout << l.size() << endl;
l.clear();
cout << l.size() << endl;
}
然后,看看这个输出:
Constructor
Destructor
Contructor
1
0
问题是:为什么不调用列表元素的析构函数l.clear()
?