codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <fstream> #include <iostream> using namespace std; class Complex { friend ostream &operator<<(ostream &, const Complex &); public: Complex (double = 0.0, double = 0.0); Complex operator+(const Complex &) const; Complex operator-(const Complex &) const; void print() const; private: double real; double imaginary; ifstream ifs;//вот что покоробит дефолт }; Complex::Complex(double realPart, double imaginaryPart) : real(realPart), imaginary(imaginaryPart) { } Complex Complex::operator+(const Complex &operand2) const { return Complex(real+operand2.real, imaginary+operand2.imaginary); } Complex Complex::operator-(const Complex &operand2) const { return Complex(real-operand2.real, imaginary-operand2.imaginary); } ostream &operator<<(ostream &output, const Complex &s) { output<<'('<<s.real<<((s.imaginary<0) ? " - j" : " + j")<<s.imaginary<<')'; return output; } int main() { Complex x; Complex y(4.3, 8.2); Complex z(3.3, -1.1); x=y+z; //почему это работает??? cout<<"\n\nx = y + z: "<<endl; cout<<x; cout<<" = "; cout<<y; cout<<" + "; cout<<z; return 0; }
Private
[
?
]
Run code
Submit