#include <iostream>
#include <string>
#include <vector>
using std::cout;
using std::endl;
std::string operator+(std::string ls, int rs) {
std::vector<char> buffer;
buffer.resize(ls.length() + 12);
sprintf(&buffer.front(), "%s%i", ls.c_str(), rs);
return std::string(&buffer.front());
}
std::string operator+(int ls, std::string rs) {
std::vector<char> buffer;
buffer.resize(rs.length() + 12);
sprintf(&buffer.front(), "%i%s", ls, rs.c_str());
return std::string(&buffer.front());
}
std::string operator+=(std::string& ls, int rs) {
ls = ls + rs;
return ls;
}
class ThreeDimPoint {
friend std::ostream& operator<<(ostream& ls, const ThreeDimPoint rs);
private:
int xpos;
int ypos;
int zpos;
public:
ThreeDimPoint();
ThreeDimPoint(int x, int y, int z);
ThreeDimPoint& set(int x, int y, int z);
};
ThreeDimPoint::ThreeDimPoint() : xpos(0), ypos(0), zpos(0) {
}
ThreeDimPoint::ThreeDimPoint(int x, int y, int z) : xpos(x), ypos(y), zpos(z) {
}
ThreeDimPoint& ThreeDimPoint::set(int x, int y, int z) {
xpos = x;
ypos = y;
zpos = z;
return *this;
}
std::ostream& operator<<(ostream& ls, const ThreeDimPoint rs) {
std::string output;
output += rs.xpos + std::string(" ");
output += rs.ypos + std::string(" ");
output += rs.zpos + std::string(" ");
ls << output;
return ls;
}
int main() {
ThreeDimPoint something( 3, 4, 5 );
cout << something << endl;
ThreeDimPoint somethingtoo;
cout << somethingtoo << endl;
somethingtoo = something;
cout << somethingtoo << endl;
somethingtoo.set( 13, 12, 9 );
cout << somethingtoo << endl;
return ( 0 );
}