[ create a new paste ] login | about

Link: http://codepad.org/nfYZgtVk    [ raw code | output | fork ]

C++, pasted on Jul 1:
#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;
}


Output:
1
2
3
/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/ios_base.h: In copy constructor 'std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)':
Line 778: error: 'std::ios_base::ios_base(const std::ios_base&)' is private
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: