Cześć!
Mam problem z klasą Complex. Mianowicie, podczas próby kompilacji wywala mi błąd:
complex2.cpp:68:1: error: ‘ostream’ does not name a type
Kod programu:
complex2.cpp:
#include "complex2.h"
#include <iostream>
using namespace std;
Complex::Complex()
{
re=0;
im=0;
}
Complex::Complex(double real, double imag)
{
this->re=real;
this->im=imag;
}
Complex Complex::operator+(const Complex & liczba2) const
{
Complex wynik;
wynik.re = this->re + liczba2.re;
wynik.im = this->im + liczba2.im;
return wynik;
}
Complex Complex::operator-(const Complex & liczba2) const
{
Complex wynik;
wynik.re = this->re - liczba2.re;
wynik.im = this->im - liczba2.im;
return wynik;
}
Complex& Complex::operator=(const Complex & liczba2)
{
this->re=liczba2.re;
this->im=liczba2.im;
return *this;
}
Complex& Complex::operator+=(const Complex & liczba2)
{
this->re=liczba2.re+this->re;
this->im=liczba2.im+this->im;
return *this;
}
Complex& Complex::operator-=(const Complex & liczba2)
{
this->re=this->re-liczba2.re;
this->im=this->im-liczba2.im;
return *this;
}
Complex Complex::operator*(const Complex & liczba2) const
{
Complex wynik;
wynik.re=this->re*liczba2.re-this->im*liczba2.im;
wynik.im=this->re*liczba2.im+this->im*liczba2.re;
return wynik;
}
Complex Complex::operator/(const Complex & liczba2) const
{
Complex wynik;
wynik.re=(this->re*liczba2.re+this->im*liczba2.im)/(liczba2.re*liczba2.re+liczba2.im*liczba2.im);
wynik.im=-(this->re*liczba2.im-this->im*liczba2.re)/(liczba2.re*liczba2.re+liczba2.im*liczba2.im);
return wynik;
}
Complex& Complex::operator/=(const Complex & liczba2){
double temp = this->re;
this->re = (this->re*liczba2.re+this->im*liczba2.im)/(liczba2.re*liczba2.re+liczba2.im*liczba2.im);
this->im = -(temp*liczba2.im-this->im*liczba2.re)/(liczba2.re*liczba2.re+liczba2.im*liczba2.im);
return *this;
}
ostream & operator<<(ostream & o,Complex &obiekt){
o << "Re: " obiekt.re << " Im: " << obiekt.im;
return o;
}
complex2.h
#ifndef COMPLEX2_H_INCLUDED
#define COMPLEX2_H_INCLUDED
class Complex
{
public:
double re;
double im;
Complex();
Complex(double real, double imag);
~Complex() {}
Complex operator+(const Complex & liczba2) const;
Complex operator-(const Complex & liczba2) const;
Complex& operator=(const Complex & liczba2);
Complex& operator+=(const Complex & liczba2);
Complex& operator-=(const Complex & liczba2);
Complex operator*(const Complex & liczba2) const;
Complex operator/(const Complex & liczba2) const;
Complex& operator/=(const Complex & liczba2);
private:
};
#endif // COMPLEX2_H_INCLUDED
W czym rzecz? using namespace std; mam zadeklarowane :/