30/05/09 9:11
frankus89
salve ragazzi!
il compilatore mi dice che nel corpo di "operator*" "re" e "im" non sono dichiarati..ma essi non dovrebbero essere passati in maniera implicita con il puntatore this?
codice:
il compilatore mi dice che nel corpo di "operator*" "re" e "im" non sono dichiarati..ma essi non dovrebbero essere passati in maniera implicita con il puntatore this?
codice:
#include <iostream> using namespace std; class Complex{ float re; float im; public: friend Complex operator+ (Complex obj); friend Complex operator* (Complex obj); Complex operator= (Complex obj); Complex(){re=im=0;}; Complex(float a, float b) { re=a; im=b;}; } Complex::Complex operator+ (Complex obj){ Complex temp; temp.re=re+obj.re; temp.im=im+obj.im; return temp; } Complex::Complex operator* (Complex obj) { Complex temp; temp.re= re * obj.re; if (im*obj.im>0) temp.im = -(im*obj.im); temp.im = im*obj.im; return temp; } Complex::Complex operator= (Complex obj){ re=obj.re; im=obj.im; return *this; int main() { Complex ob(3,-6); Complex ob1(3,6); Complex k; k = ob + ob1; return 0; }
aaa