Created
October 27, 2013 15:59
-
-
Save jeffcrouse/7184185 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
// tostring2.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; | |
} | |
operator string() { | |
char str[255]; | |
sprintf(str, "Rectangle(x=%.2f, y=%.2f, width=%.2f, height=%.2f)", x, y, width, height); | |
return string( str ); | |
} | |
float x, y; | |
float width, height; | |
}; | |
int main () | |
{ | |
Rectangle r; | |
r.init(10, 20, 30, 40); | |
cout << (string)r << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment