Operator overloading
-
Hallo I have written some class
#if !defined(_COMPLEX_H_) #define _COMPLEX_H_ #include <stdio.h> #include <iostream.h> class Complex { public: Complex(); Complex(const Complex&); Complex(double a, double b) : re(a), im(b) {} virtual ~Complex(); // Complex += Complex const Complex& operator+= (const Complex&); // Cpmplex += Zahl const Complex& operator+= (const double); // Zahl += Complex friend Complex operator+= (double&, Complex&); // Comlex + Complex Complex operator+ (const Complex&) const; // Complex + Zahl Complex operator+ (const double) const; // Zahl + Complex friend Complex operator+ (double, const Complex&); // Complex -= Complex const Complex& operator-= (const Complex&); // Complex -= Zahl const Complex& operator-= (const double); // Zahl -= Complex friend Complex operator-= (double, Complex&); // Complex - Complex Complex operator- (const Complex&) const; // Complex - Zahl Complex operator- (const double) const; // Zahl - Complex friend Complex operator- (double, const Complex&); // Konjunktion Complex operator! (void); // Ausgabe einer Complexenzahl friend ostream& operator<< (ostream&,const Complex&); private: double re; double im; }; #endif
How to change this operator to global calling and then referencing in the class complex ??? THX T -
Hallo I have written some class
#if !defined(_COMPLEX_H_) #define _COMPLEX_H_ #include <stdio.h> #include <iostream.h> class Complex { public: Complex(); Complex(const Complex&); Complex(double a, double b) : re(a), im(b) {} virtual ~Complex(); // Complex += Complex const Complex& operator+= (const Complex&); // Cpmplex += Zahl const Complex& operator+= (const double); // Zahl += Complex friend Complex operator+= (double&, Complex&); // Comlex + Complex Complex operator+ (const Complex&) const; // Complex + Zahl Complex operator+ (const double) const; // Zahl + Complex friend Complex operator+ (double, const Complex&); // Complex -= Complex const Complex& operator-= (const Complex&); // Complex -= Zahl const Complex& operator-= (const double); // Zahl -= Complex friend Complex operator-= (double, Complex&); // Complex - Complex Complex operator- (const Complex&) const; // Complex - Zahl Complex operator- (const double) const; // Zahl - Complex friend Complex operator- (double, const Complex&); // Konjunktion Complex operator! (void); // Ausgabe einer Complexenzahl friend ostream& operator<< (ostream&,const Complex&); private: double re; double im; }; #endif
How to change this operator to global calling and then referencing in the class complex ??? THX T -
Hallo I have written some class
#if !defined(_COMPLEX_H_) #define _COMPLEX_H_ #include <stdio.h> #include <iostream.h> class Complex { public: Complex(); Complex(const Complex&); Complex(double a, double b) : re(a), im(b) {} virtual ~Complex(); // Complex += Complex const Complex& operator+= (const Complex&); // Cpmplex += Zahl const Complex& operator+= (const double); // Zahl += Complex friend Complex operator+= (double&, Complex&); // Comlex + Complex Complex operator+ (const Complex&) const; // Complex + Zahl Complex operator+ (const double) const; // Zahl + Complex friend Complex operator+ (double, const Complex&); // Complex -= Complex const Complex& operator-= (const Complex&); // Complex -= Zahl const Complex& operator-= (const double); // Zahl -= Complex friend Complex operator-= (double, Complex&); // Complex - Complex Complex operator- (const Complex&) const; // Complex - Zahl Complex operator- (const double) const; // Zahl - Complex friend Complex operator- (double, const Complex&); // Konjunktion Complex operator! (void); // Ausgabe einer Complexenzahl friend ostream& operator<< (ostream&,const Complex&); private: double re; double im; }; #endif
How to change this operator to global calling and then referencing in the class complex ??? THX T -
Hallo I have written some class
#if !defined(_COMPLEX_H_) #define _COMPLEX_H_ #include <stdio.h> #include <iostream.h> class Complex { public: Complex(); Complex(const Complex&); Complex(double a, double b) : re(a), im(b) {} virtual ~Complex(); // Complex += Complex const Complex& operator+= (const Complex&); // Cpmplex += Zahl const Complex& operator+= (const double); // Zahl += Complex friend Complex operator+= (double&, Complex&); // Comlex + Complex Complex operator+ (const Complex&) const; // Complex + Zahl Complex operator+ (const double) const; // Zahl + Complex friend Complex operator+ (double, const Complex&); // Complex -= Complex const Complex& operator-= (const Complex&); // Complex -= Zahl const Complex& operator-= (const double); // Zahl -= Complex friend Complex operator-= (double, Complex&); // Complex - Complex Complex operator- (const Complex&) const; // Complex - Zahl Complex operator- (const double) const; // Zahl - Complex friend Complex operator- (double, const Complex&); // Konjunktion Complex operator! (void); // Ausgabe einer Complexenzahl friend ostream& operator<< (ostream&,const Complex&); private: double re; double im; }; #endif
How to change this operator to global calling and then referencing in the class complex ??? THX T -
Hi i'd like to achive that there are not that many functions so changes might be easier to make I know that it is possible to get the same behavior by using 4 global funktions and torefere by using friend. But i dont know hoe to manage T
tbrake wrote:
I know that it is possible to get the same behavior by using 4 global funktions...
In addition to, or in lieu of, the class methods?
tbrake wrote:
...and torefere by using friend.
Doesn't your class already have
friend
functions?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
-
tbrake wrote:
I know that it is possible to get the same behavior by using 4 global funktions...
In addition to, or in lieu of, the class methods?
tbrake wrote:
...and torefere by using friend.
Doesn't your class already have
friend
functions?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
Year your right !?! But whenever i try something like
Complex operator! (double&, Complex&); class Complex { ... };
I receive some errors! And second isn't ist possible to combine all "+" or "+=" ... functions so that there is only one to modify and not like the class i posted changeing always 3 methods ?? T -
Year your right !?! But whenever i try something like
Complex operator! (double&, Complex&); class Complex { ... };
I receive some errors! And second isn't ist possible to combine all "+" or "+=" ... functions so that there is only one to modify and not like the class i posted changeing always 3 methods ?? Ttbrake wrote:
I receive some errors!
What errors?
class Complex
{
...
};Complex operator!( double&, Complex& );
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli