By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,650 Members | 1,785 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,650 IT Pros & Developers. It's quick & easy.

Use of return_type in definition of function object

P: n/a
Am I missing some sort of declaration or is there a syntax error in
the definition of the binary function object "less_metric1" below? My
compiler says: "ISO C++ forbids declaration of `return_type' with no
type."

Thanks, Alan
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;

class measurement
{
public:
double metric1, metric2, metric3;
};

class less_metric1 : binary_function<measurement, measurement, bool>
{
public:
return_type operator()(const measurement& a, const measurement& b)
{
return a.metric1 < b.metric1;
}
};

int main()
{
// Create objects
measurement data1, data2, data3;
data1.metric1 = 1; data1.metric2 = 2; data1.metric3 = 3;
data2.metric1 = 2; data2.metric2 = 3; data2.metric3 = 1;
data3.metric1 = 3; data3.metric2 = 2; data3.metric3 = 1;

system("PAUSE");
}

Jun 18 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Never mind! "return_type" is not a keyword, so apparently I needed
the actual return type of "bool".
Jun 18 '07 #2

P: n/a
Alan a écrit :
Never mind! "return_type" is not a keyword, so apparently I needed
the actual return type of "bool".
"result_type" is acceptable because of binary_function<traits:
namespace std {
template <class Arg1, class Arg2, class Result>
struct binary_function{
typedef Arg1 first_argument_type;
typedef Arg2 second_argument_type;
typedef Result result_type;
};
}
Jun 18 '07 #3

P: n/a
Then, it should compile? Changing it made it compile but not work as
intended.

Did I get the syntax wrong or something?

Thanks, Alan

Jun 18 '07 #4

P: n/a
Alan a écrit :
Then, it should compile? Changing it made it compile but not work as
intended.

Did I get the syntax wrong or something?
I cannot say since I don't knwwo what you mean by "not work as intended".
How did you use it ?

Michael
Jun 18 '07 #5

P: n/a
Alan wrote:
Am I missing some sort of declaration or is there a syntax error in
the definition of the binary function object "less_metric1" below? My
compiler says: "ISO C++ forbids declaration of `return_type' with no
type."
sure, because the actual name for the return type is result_type, not
return_type. ;)

Regards,

Zeppe
Jun 18 '07 #6

P: n/a
Duh!! Thanks! Alan
Jun 18 '07 #7

P: n/a
On Jun 19, 2:04 am, Alan <jalantho...@verizon.netwrote:
class less_metric1 : binary_function<measurement, measurement, bool>
{
public:
return_type operator()(const measurement& a, const measurement& b)
{
return a.metric1 < b.metric1;
}
};
I think you should be using public derivation here
(the default is private for 'class').

Jun 18 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.