Re: storing location, to variables, one return type


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by William D McQuain on April 19, 2001 at 17:46:37:

In Reply to: storing location, to variables, one return type posted by Nathan on April 18, 2001 at 20:58:20:

: In the container class, lifeform, I have somethign like getLocation. I need to return location, but it is two seperate integers, xloc and yloc. I guess I could my location into a small struct, a two dimensional array, or even a string and use stringstream, but is there a better way? Is there a way to return two variables rather than just one? I'd rather not create another data structure just for the location as my head is already swimming in abstract classes, base classes, derived classes, pointers, etc etc etc

: Thanks


OK, now that the chorus has spoken, consider this:

class Location {
private:
int xLoc;
int yLoc;
public:
Location();
Location(int initX, int initY);
bool operator==(const Location& Other);
int atX() const;
int atY() const;
void Up();
void Down();
void Left();
void Right();

friend ostream& operator<<(ostream& Out, const Location& Loc);
};




Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]