But how implement operator+ *without a copy* in a C++ class, or in C?
class num1 (if I read well) doesn't use copy (I use &) but don't work
because if I do
num1 x, a("100"), b("777");
x= a*b;
although inside operator* seems to be ok in operator= is KO. Why?
class num10 seems ok;
class num10{
friend int operator==(const num10& a, const num10& b);
friend int operator<( const num10& a, const num10& b);
friend int operator>( const num10& a, const num10& b);
friend int operator<=(const num10& a, const num10& b);
friend int operator>=(const num10& a, const num10& b);
friend int operator!=(const num10& a, const num10& b);
friend int operator==(const num10& a, unsigned b);
friend int operator<( const num10& a, unsigned b);
friend int operator>( const num10& a, unsigned b);
friend int operator<=(const num10& a, unsigned b);
friend int operator>=(const num10& a, unsigned b);
friend int operator!=(const num10& a, unsigned b);
friend int operator==(unsigned a, const num10& b);
friend int operator<( unsigned a, const num10& b);
friend int operator>( unsigned a, const num10& b);
friend int operator<=(unsigned a, const num10& b);
friend int operator>=(unsigned a, const num10& b);
friend int operator!=(unsigned a, const num10& b);
friend num10 operator+( const num10& a, const num10& b);
friend num10 operator+( const num10& a, unsigned b);
friend num10 operator+( unsigned b, const num10& a);
friend num10 operator-( const num10& a, const num10& b);
friend num10 operator-( const num10& a, unsigned b);
friend num10 operator-( unsigned b, const num10& a);
friend num10 operator*( const num10& a, const num10& b);
friend num10 operator*( const num10& a, unsigned b);
friend num10 operator*( unsigned b, const num10& a);
friend num10 operator/( const num10& a, const num10& b);
friend num10 operator/( const num10& a, unsigned b);
friend num10 operator/( unsigned b, const num10& a);
friend num10 operator%( const num10& a, const num10& b);
friend num10 operator%( const num10& a, unsigned b);
friend num10 operator%( unsigned b, const num10& a);
friend int resize( unsigned len);
friend void pr_num( const num10& a );
public :
num10();
num10(unsigned len);
num10(const char a[]);
num10(num10& r);
num10& operator=(const num10& r);
num10& operator=(unsigned r);
~num10();
numero* nume() { R &numer; }
unsigned char* ricon1();
void print();
private:
numero numer;
unsigned lung;
};
class num1{
friend int operator==(const num1& a, const num1& b);
friend int operator<( const num1& a, const num1& b);
friend int operator>( const num1& a, const num1& b);
friend int operator<=(const num1& a, const num1& b);
friend int operator>=(const num1& a, const num1& b);
friend int operator!=(const num1& a, const num1& b);
friend int operator==(const num1& a, unsigned b);
friend int operator<( const num1& a, unsigned b);
friend int operator>( const num1& a, unsigned b);
friend int operator<=(const num1& a, unsigned b);
friend int operator>=(const num1& a, unsigned b);
friend int operator!=(const num1& a, unsigned b);
friend int operator==(unsigned a, const num1& b);
friend int operator<( unsigned a, const num1& b);
friend int operator>( unsigned a, const num1& b);
friend int operator<=(unsigned a, const num1& b);
friend int operator>=(unsigned a, const num1& b);
friend int operator!=(unsigned a, const num1& b);
friend num1& operator+( const num1& a, const num1& b);
friend num1& operator+( const num1& a, unsigned b);
friend num1& operator+( unsigned b, const num1& a);
friend num1& operator-( const num1& a, const num1& b);
friend num1& operator-( const num1& a, unsigned b);
friend num1& operator-( unsigned b, const num1& a);
friend num1& operator*( const num1& a, const num1& b);
friend num1& operator*( const num1& a, unsigned b);
friend num1& operator*( unsigned b, const num1& a);
friend num1& operator/( const num1& a, const num1& b);
friend num1& operator/( const num1& a, unsigned b);
friend num1& operator/( unsigned b, const num1& a);
friend num1& operator%( const num1& a, const num1& b);
friend num1& operator%( const num1& a, unsigned b);
friend num1& operator%( unsigned b, const num1& a);
friend int resize1( unsigned len);
friend num10 conv(const num1& a);
friend num1& sqrt(const num1& a);
friend num1& gcd (const num1& a, const num1& b);
public :
num1();
num1(unsigned len);
num1(const char a[]);
num1(num1& r);
num1& operator=(num1* r);
num1& operator=(const num1& r);
num1& operator=(unsigned r);
~num1();
void print();
void prin();
void casuale(unsigned len);
private:
num_s numer;
unsigned lung;
};