>What I wanted to know is how to have the same effect as what I was trying.
Here's a quickie solution, apologies for the crudity:
Code:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <limits>
class Integer
{
char base[std::numeric_limits<int>::digits + 1];
public:
Integer ( int i ) { sprintf ( base, "%d", i ); }
operator int()
{
return atoi ( base );
}
Integer& operator= ( const Integer& i )
{
sprintf ( base, "%s", i.base );
return *this;
}
Integer& operator+= ( int rhs )
{
int hold = atoi ( base ) + rhs;
sprintf ( base, "%d", hold );
return *this;
}
friend std::ostream operator<< ( std::ostream out, const Integer& i )
{
return out<< i.base;
}
};
const Integer operator+ ( const Integer& lhs, int rhs )
{
return Integer ( lhs ) += rhs;
}
int main()
{
int a = 5;
Integer i = 10;
std::cout<< i <<std::endl;
i += 5;
std::cout<< i <<std::endl;
i = i + 5;
std::cout<< i <<std::endl;
a += i;
std::cout<< a <<std::endl;
}
-Prelude