C
CS
Hi,
How do you pass a function pointer as an argument?
I have the following:
class FReport
{
...
};
// function object used to retrieve reports
//------------------------------------------------------------
class FindReportByID : public std::unary_function<FReport*, bool>
{
public:
FindReportByID(STD_int id): m_ID(id) {};
inline bool operator () (const FReport* pReport) const;
private:
const STD_int m_ID;
};
and the function to find a report using a function object:
FReport* findReport(std::unary_function<FReport*,bool>&
rFunctionObject) const
{
// ReportIt is a typedef list iterator
const ReportIt pos = std::find_if(m_reports.begin(),
m_reports.end(), rFunctionObject);
return *pos;
}
(The idea is to have a function that finds something using a given
function object)
and what I try to do:
int id = 1; // a report id
FindReportByID findByID(id); // my function object
FReport* pReport = findReport(findByName); // ???!!!! error here C2064:
term does not evaluate to a function
What am I doing wrong?
Thanks.
How do you pass a function pointer as an argument?
I have the following:
class FReport
{
...
};
// function object used to retrieve reports
//------------------------------------------------------------
class FindReportByID : public std::unary_function<FReport*, bool>
{
public:
FindReportByID(STD_int id): m_ID(id) {};
inline bool operator () (const FReport* pReport) const;
private:
const STD_int m_ID;
};
and the function to find a report using a function object:
FReport* findReport(std::unary_function<FReport*,bool>&
rFunctionObject) const
{
// ReportIt is a typedef list iterator
const ReportIt pos = std::find_if(m_reports.begin(),
m_reports.end(), rFunctionObject);
return *pos;
}
(The idea is to have a function that finds something using a given
function object)
and what I try to do:
int id = 1; // a report id
FindReportByID findByID(id); // my function object
FReport* pReport = findReport(findByName); // ???!!!! error here C2064:
term does not evaluate to a function
What am I doing wrong?
Thanks.