I am trying to generalize the functions filterX()
and filterY()
in the following class Table
to function filter()
.
If you want to use explicit PMF ( or at least see how they are used):
Declare the PMF type:
class Row
{
public:
typedef string (Row::*getFilter)() const;
// etc.
};
class Table
{
public:
// Call it like this:
vector pmf_filterX(string s)
{
return filter(s, &Row::getX);
}
private:
// Use it like this:
vector filter(string s, Row::getFilter f)
{
vector result;
vector::iterator it;
for(it = d_table.begin(); it != d_table.end(); ++it)
{
const Row& row = *it;
if ((row.*f)() == s)
{
int val = it->getVal();
result.push_back(val);
}
}
return result;
}
};