Original Post
My code is suppost to return point that has the largest value, instead it always returns 0 why?
Any help would be appreciated.
Edited by - David McCaleb on 10/21/00 1:10:36 PM
//Here is the point class:
class Point
{
public:
Point(unsigned short x = 0, unsigned short y = 0, short value = 1): itsx(x), itsy(y), itsvalue(value) {}
~Point() {}
unsigned short GetItsX() {return itsx;}
void SetItsX(unsigned short x) {itsx = x;}
unsigned short GetItsY() {return itsy;}
void SetItsY(unsigned short y) {itsy = y;}
short GetItsValue() {return itsvalue;}
void SetItsValue(short value) {itsvalue = value;}
private:
unsigned short itsx;
unsigned short itsy;
short itsvalue;
};
//Here is the function:
Point * Largest(Point * pointlist)
{
int n = sizeof pointlist/sizeof pointlist[0];
int max = 0;
for(int i = 0; i < n; i++)
{
if(pointlist<i>.GetItsValue() == -1)
max = i;
if(pointlist[i].GetItsValue() > pointlist[max].GetItsValue())
max = i;
}
return &pointlist[max];
}
|