class Student {
bool Graduate() { return m_bGraduate; }
};
class School {
vector<Student*> m_vecStudents;
void DelAndNullify(Student* &pStd);
void Fun1();
};
void School::DelAndNullify(Student* &pStd)
{
if ( (pStd != NULL) && (pStd->Graduate()) )
{
delete pStd;
pStd = NULL;
}
}
void School::Fun1()
{
for_each(m_vecStudents.begin(), m_vecStudents.end(), mem_fun(&School::DelAndNullify));
}
Error 1 error C2064: the term does not evaluate a function that takes 1 argument C: \ Program Files \ Microsoft Visual Studio 10.0 \ VC \ include \ algorithm 22 1 Modeling
Why am I getting this error?
updated
change StudenttopStd
updated // algorithm file
template<class _InIt, class _Fn1> inline
_Fn1 _For_each(_InIt _First, _InIt _Last, _Fn1 _Func)
{
for (; _First != _Last; ++_First)
_Func(*_First);
return (_Func);
}
By the way, if I define DelAndNullifyas static, then the next line passes the compiler
for_each(m_vecStudents.begin(), m_vecStudents.end(), ptr_fun(&School::DelAndNullify));
Updated 09/05/2012
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <iostream>
#include <iomanip>
#include <functional>
#include <boost/bind.hpp>
class Student {
public:
Student(int id, bool bGraduate) : m_iID(id), m_bGraduate(bGraduate) {}
bool Graduate() const { return m_bGraduate; }
private:
int m_iID;
bool m_bGraduate;
};
class School {
public:
School(int numStudent)
{
for (int i=0; i<numStudent; ++i)
{
m_vecStudents.push_back(new Student(i+1, false));
}
}
~School()
{
}
void DelAndNullify(Student* &pStd);
void Fun1();
private:
std::vector<Student*> m_vecStudents;
};
void School::DelAndNullify(Student* &pStd)
{
if ( (pStd != NULL) && (!pStd->Graduate()) )
{
delete pStd;
pStd = NULL;
}
}
void School::Fun1()
{
std::for_each(m_vecStudents.begin(), m_vecStudents.end(), std::bind1st(std::mem_fun(&School::DelAndNullify), this));
}
int main(int , char* [])
{
School school(10);
school.Fun1();
return 0;
}
Error 1 error C2535: 'void std :: binder1st <_Fn2> :: operator () (Student * &) const': member function is already defined or declared c: \ Program Files \ Microsoft Visual Studio 10.0 \ VC \ include \ xfunctional 299
q0987 source
share