Created
October 27, 2013 15:58
-
-
Save jeffcrouse/7184171 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
| // tostring.cpp | |
| #include <iostream> | |
| using namespace std; | |
| class Rectangle { | |
| public: | |
| void init(float _x, float _y, float _width, float _height) { | |
| x = _x; | |
| y = _y; | |
| width = _width; | |
| height = _height; | |
| } | |
| friend ostream& operator<<(ostream&, const Rectangle&); // optional | |
| float x, y; | |
| float width, height; | |
| }; | |
| ostream& operator<<(ostream &strm, const Rectangle &r) { | |
| return strm << "Rectangle(x=" << r.x << ", y=" << r.y << ", width=" << r.width << ", height=" << r.height << ")"; | |
| } | |
| int main () | |
| { | |
| Rectangle r; | |
| r.init(10, 20, 30, 40); | |
| cout << r << endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment