I have a struct
struct doodle
{
int x;
int y;
};
and 2 methods that are identical, except they make use of different attributes of struct doodle:
void ProcessDoodlesHorizontally(std::vector<struct doodle>& v_doodles)
{
for (unsigned int i=0; i<v_doodles.size(); i++)
{
int x = v_doodles.at(i).x;
std::cout<<x<<std::endl;
}
}
void ProcessDoodlesVertically(std::vector<struct doodle>& v_doodles)
{
for (unsigned int i=0; i<v_doodles.size(); i++)
{
int y = v_doodles.at(i).y;
std::cout<<y<<std::endl;
}
}
I would like to make a function ProcessDoodlesGeneric which can take as argument info about whether I am interested in doodle.x or doodle.y. Is this possible? If not, what are alternative ways to reuse code in this example?
boolargument that lets it know whether to do a or b.