Overloaded < and > operators

Hi, I'm trying to overload the < and > operators to compare two objects but when I try to use them, nothing happens.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Overloaded > operator
bool StudentRecord::operator>(StudentRecord& ref){		
	cout<<"IN > OP"<<endl;return m_mark > ref.GetMark();
}

// Overloaded < operator
bool StudentRecord::operator<(StudentRecord& ref){		
	cout<<"IN > OP"<<endl;return m_mark < ref.GetMark();
}

when I compare I use the following code:
for(int i=0;i<m_numRecords;i++){
    if(m_ppRecords[i]>highest)
        highest = m_ppRecords[i];  // Here I use overload assignment which works
}                                     // how it's suppose to 

example
1
2
3
4
5
6
bool operator > (const AllNumbers & right) const;
bool operator > (int right) const;
bool operator > (double right) const;
bool operator < (const AllNumbers & right) const;
bool operator < (int right) const;
bool operator < (double right) const;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
bool AllNumbers::operator < (const AllNumbers & right) const {
	return !(*this > right);
}

bool AllNumbers::operator < (int right) const {
	return !(*this > right);
}

bool AllNumbers::operator < (double right) const {
	return !(*this > right);
}

bool AllNumbers::operator > (const AllNumbers & right) const {
	int result1, result2;
	result1 = dividend * right.divisor;
	result2 = right.dividend * divisor;
	return result1 > result2;
}

bool AllNumbers::operator > (int right) const {
	right *= divisor;
	return dividend > right;
}

bool AllNumbers::operator > (double right) const {
	double result1;
	result1 = (double)dividend / (double)divisor;
	return result1 > right;
}


This is from class I set up, learning operator and function overloading.
Last edited on
Topic archived. No new replies allowed.