Skip to content

Instantly share code, notes, and snippets.

@jeffcrouse
Created October 27, 2013 15:59
Show Gist options
  • Save jeffcrouse/7184185 to your computer and use it in GitHub Desktop.
Save jeffcrouse/7184185 to your computer and use it in GitHub Desktop.
// 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