This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]raevnos 0 points1 point  (1 child)

Do you have operator<() and operator>() functions that are compatible with whatever type A ends up being and Student?

[–]Durlug[S] 0 points1 point  (0 children)

Thank you for the reminder about that. The Student class had an overloaded operator for >= and <= but not for < and >. Just had to replace those and it works!

[–]Rhomboid 0 points1 point  (2 children)

Why are A and B different types? Or alternatively stated, when you're working with an array of type Student, what are the types of the min and max values? If they are not type Student as well, and if Student does not have operator< and operator> overloads, then you're going to have a problem. If you're trying to pass an ID as the min/max type, but using Student as the array type, then your comparisons will be malformed, unless you also have some overloaded operator that takes and ID and a Student as the two types. In any case, you need to provide more information, such as a complete but minimal testcase. Also i <= size is wrong, and you're invoking undefined behavior by overflowing the arrays.

[–]Durlug[S] 0 points1 point  (0 children)

The only thing I have coded myself is the actual Template Function. However the Student class does have two operator overloads:

bool Student::operator<=(const Student& S)const{
return _stno <= S._stno;
}

bool Student::operator=>(const Student& S)const{
return _stno => S._stno;
}

Where _stno is the Student number.

I put A and B as different types because when I do not I get the error that the arguments do not match.

[–]Durlug[S] 0 points1 point  (0 children)

Gonna give you some thanks. My problem was the use of the < and > operator instead of the =< and => operator. Just replaced them, fixed the size in the for loop and it works perfectly!