struct SomeStruct
{
};
class C
{
public:
C()
{
for (int i = 0; i < 100; ++i)
{
m_List.push_back(new SomeStruct);
}
}
private:
std::list<SomeStruct*> m_List;
};
析构函数的两种变体中的哪一种更快(为什么?)以释放内存:
~C()
{
for (auto iter = m_List.begin(); iter != m_List.end(); ++iter)
{
delete *iter;
}
}
~C()
{
while (m_List.size() != 0)
{
delete *m_List.begin();
m_List.pop_front();
}
}