I am trying to generalize the functions filterX()
and filterY()
in the following class Table
to function filter()
.
Modify your code here:
public:
void add(string x, string y, int val);
vector filter(string s, string (Row::*)() const);
private:
...
Here:
vector Table::filter(string s, string (Row::*f)() const)
{
vector result;
vector::iterator it;
for(it = d_table.begin(); it != d_table.end(); ++it) {
if((*it.*f)() == s) {
int val = it->getVal();
result.push_back(val);
}
}
return result;
}
And here:
int main()
{
...
vector vx = t.filter("x1", &Row::getX);
vector vy = t.filter("y2", &Row::getY);
...