473,466 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Use of return_type in definition of function object

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
7 2031
Never mind! "return_type" is not a keyword, so apparently I needed
the actual return type of "bool".
Jun 18 '07 #2
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
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
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
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
Duh!! Thanks! Alan
Jun 18 '07 #7
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jerry | last post by:
My "main" class is getting a bit long...Is it possble to split a class definition into several files and then import the pieces to get the whole definition? Jerry
0
by: Jimmy Cerra | last post by:
I recently came up with a cool little stylesheet for definition lists. There is a small demostration for the impatient . I hope this helps someone. Here's how I did it. Definition lists are...
19
by: J. J. Farrell | last post by:
After many years of dealing with definition and linkage issues in ways that I know to be safe, I've decided it's time to try to understand this area properly. Consider a header file with the file...
10
by: Kobu | last post by:
My question is about the use and meaning of the terms "declaration" and "definition" as it pertains to the C language. I've read sources that mix the two up when talking about such things as...
11
by: Old Wolf | last post by:
Does the following program require a diagnostic? Which section of the Standard deals with this? (I read the section on function calls and didn't see anything). void f(void); int main(void) {...
15
by: vaib | last post by:
hi to all.i'd like to know the actual difference between variable declaration and definition.it would be very helpful if anyone out there wud help me out with this thing.i'm writing here after here...
15
by: mdh | last post by:
May I ask. If an array is defined , not as a static, but outside of a function, is there any guarantee as to the contents of each element? Thanks.
19
by: liketofindoutwhy | last post by:
I did some animation using var oDiv = {}; oDiv.x = 100; oDiv.y = 100; oDiv.node = document.getElementById('divImage'); oDiv.node.style.position = "absolute"; oDiv.doAnimation = function()...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.