#include <list>
#include <algorithm>
class Abstract
{
//contains a pure virtual function
};
class Mock
{
public:
Mock();
~Mock()
{
std::for_each(m_abs_list.begin(), m_abs_list.end(), my_func);
}
void my_func(Abstract *ele){delete ele;}
private:
std::list <Abstract *> m_abs_list;
};
Basically, I am trying to call the destructor for each Abstract
object in the m_abs_list
. This can be easily achieved by a for
loop. But I am trying to used for_each
in this context.
On compilation I get error:
/usr/include/c++/4.2/bits/stl_algo.h: In function '_Function std::for_each(_InputIterator, _InputIterator, _Function) [with _InputIterator = std::_List_iterator<Abstract *>, _Function = void (Mock::*)(Abstract *)]'
/usr/include/c++/4.2/bits/stl_algo.h:159: error: must use '.*' or '->*' to call pointer-to-member function in '__f (...)'.
How do i get around the compilation error ?