Operator overloading return

Hello, I am doing an assignment for school and was wondering if it possible to return an overload. Specifically can you return a conditional overload by calling the overload on the return and then negating it? Crudely speaking:

Bool operator>=(parameters)
{
//some code
}

Bool operator<(Parameters)
{
Return!( parameter > parameter2)
}
let's go through the code in steps, with some clean-up of the text:
1
2
3
4
5
6
7
8
9
10
11
12
13

bool operator >= (const parameters& rhs)
{
	return *this.some_attribute >= rhs.some_attribute;
}

bool operator < (const parameters& rhs)
{
	return !(*this >= rhs); // >=, NOT >
	//the bit within the brackets was just overloaded above and returns bool
	// and we can take negation of bool which is also bool
	//so the answer to your query is yes, it can be done 
}

edit: above assumes you're sorting >= and < both on the basis of the same data member some_attribute
Last edited on
Topic archived. No new replies allowed.