
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















class Complex{ private: double real, img; public: …
Complex operator +(const Complex & rhs); };
Complex t = c1 + c2 + c3;
(c1.operator +(c2)).operator +(c3);
with reference to the left hand
argument
class Complex{
...
Complex operator+(const Complex & rhs);
Complex operator+(const double& rhs);
};
Complex operator + (const double& rhs){ Complex t; t.real = real + rhs; t.img = img; return t;
}
Complex c5 = 450.120 + c1;
Class Complex{
… friend Complex operator + (const Complex & lhs, const double & rhs); friend Complex operator + (const double & lhs, const Complex & rhs);
}
Complex operator + (const double &
lhs, const Complex & rhs){
Complex t; t.real = lhs + rhs.real; t.img = rhs.img; return t;
}
Class Complex{
… Complex operator + (const Complex &); friend Complex operator + (const Complex &, const double &); friend Complex operator + (const double &, const Complex &);
};
String::String(char * ptr){ if(ptr != NULL){ size = strlen(ptr); bufferPtr = new char[size+1]; strcpy(bufferPtr, ptr); } else{ bufferPtr = NULL; size = 0; } }
int main(){
String str1(“Hello"); String str2(“World”); str1 = str2; return 0;
}
Member wise copy assignment
Hello
World