The book asks me to do the following:
Note that the function from the previous exercise and the functions from §6.2.2/113 and
§6.2.3/115 do the same task. Merge these three analysis functions into a single function.

the three functions are:

``````double average_analysis(const vector<Student_info>& students)
{

transform(students.begin(), students.end(),

}``````
``````double median_analysis(const vector<Student_info>& students)
{

transform(students.begin(), students.end(),

}``````
``````double optimistic_median_analysis(const vector<Student_info>& s)
{

}``````

The only thing that differs if the parameter(which are functions) the function uses in the transform part

Can anyone give me any hints on how to do what he asks ?

is there a way to make that function calling "generic" so I can choose it later ... using only one analysis function ?

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by mitrious

Everything is the same except the last parameter to 'transform'.

So why don't you pass this argument to 1 analysis function?

``````double analysis( const vector<Student_info>& s, type_of_last_param_to_transform t )
{
...
}``````

I've intentionally left out the type of the last parameter to transform, I assume you can find out what the type of that parameter is.

Everything is the same except the last parameter to 'transform'.

So why don't you pass this argument to 1 analysis function?

``````double analysis( const vector<Student_info>& s, type_of_last_param_to_transform t )
{
...
}``````

I've intentionally left out the type of the last parameter to transform, I assume you can find out what the type of that parameter is.

That's what I'd tried:

``````double generic_analysis(const vector<Student_info>& s,double t(const Student_info&))
{
transform(s.begin(), s.end(),
return 0;
}``````

and when I called like: "generic_analysis(did, grade_aux);" , for example ... (did being a vector<Student_info>) it only gives me 0 as an answer ... no matter what are the values inside did.

that's why I asked here ... I can't find what I'm doing wrong =S

You should create a pointer to function, and then pass the functions address with a reference.

You should create a pointer to function, and then pass the functions address with a reference.

I haven't got to the part of the book where it deals with pointers ... so I assume there's another way to do so ... any ideas?

Well, I solved it ... thx for your help guys ... the problem was on the second call to these functions ... now it works ... =D thx

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.