Created
December 4, 2011 21:48
-
-
Save paxswill/1431394 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Point{ | |
| public: | |
| // Public member functions here | |
| int getX(){ | |
| return this.x; | |
| } | |
| // Other accessors here | |
| // There are two ways to go about checking equality. | |
| // This first way is simpler, but not really used once | |
| // people get the hang of Operator overloading (http://www.cplusplus.com/doc/tutorial/classes2/) | |
| // Frankly, I don't really get operator overloading, but | |
| // if your teacher taught them (well, if they were supposed to) | |
| // you'll probably be expected to use them. | |
| // First, the easy way: | |
| bool equals(Point &other){ | |
| return this.x == other.getX() && this.y == other.getY(); | |
| } | |
| // This just returns a boolean if both internal data values are the same | |
| // the hard way: | |
| bool operator==(const Point &other) const{ | |
| return this.x == other.getX() && this.y == other.getY(); | |
| } | |
| // Functionally, this is the same as the easy way, but it allows you | |
| // to do things like | |
| // Points a and b are defined by now | |
| if(a == b){ | |
| // do something | |
| } | |
| // Where before you would do | |
| if(a.equals(b)){ | |
| // do something | |
| } | |
| // Major Note: I haven't tested any of what I just wrote, and there could be some big typos | |
| private: | |
| // Private member data here | |
| int x; | |
| int y; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment