I have been working on an exercise in Accelerated C++ which shows how to use an auxiliary function to call an overloaded function when using transform.
grade is an overloaded function, so this won't work:
transform(stude nts.begin(), students.end(), back_inserter(g rades), grade);
So, as a workaround, we create an auxiliary function double grade_aux(const Student_info& s) that returns the particular overloaded function we want, grade(s). So now we have a transform call that works:
transform(stude nts.begin(), students.end(), back_inserter(g rade), grade_aux);
My question is, why couldn't we have saved a step and simply used:
transform(stude nts.begin(), students.end(), back_insterter( grade), grade(s));
or something like that to specify which version of our overloaded function we want to call?
grade is an overloaded function, so this won't work:
transform(stude nts.begin(), students.end(), back_inserter(g rades), grade);
So, as a workaround, we create an auxiliary function double grade_aux(const Student_info& s) that returns the particular overloaded function we want, grade(s). So now we have a transform call that works:
transform(stude nts.begin(), students.end(), back_inserter(g rade), grade_aux);
My question is, why couldn't we have saved a step and simply used:
transform(stude nts.begin(), students.end(), back_insterter( grade), grade(s));
or something like that to specify which version of our overloaded function we want to call?
Comment