似乎很简单的问题,但我很怀疑。当我调用使用运算符创建的非空列表时,运算符会delete
销毁所有 Object
元素吗?当然会,但我需要确认。如您所见,有构造函数,但没有分发器。delete list
new
Object
代码:
std::list<Object>* ptr_listObjects = new std::list<Object>();
OtherObject* ptr_null = NULL;
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
delete ptr_listObjects; // no any possible memory leaks? (Object does not use `new` operator)
class Object
{
public:
Object( OtherObject* ptr_other, char xxx):
ptr_OtherObject(ptr_other),
charflag(xxx)
{}
OtherObject* ptr_OtherObject;
char charflag;
};