Magog
Početnik
- Poruka
- 36
Ovako stvari stoje, ja se ucim C++ i evo na pocetku naidjoh na jedan problemcic. Ukucam ovaj kod, koji je primer iz neke knjige, uneo sam novine s ciljem da U/I podataka izvodim preko objekata klase 'istreajm' ali nesto ne valja sa cin-om, dok je sa cout-om sve OK jer sam uneo podatke preko konstruktora. Naime, kad kompajlira fajl javlja mi gresku:
D:\MyProjects\kompleksni brojevi\kompleks.cpp(63) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class Complex (__cdecl *)(void)' (or there is no acceptable conversion)
i ovo pokazuje na liniju koda gde je 'cin'
Sta moze da bude?
include <iostream.h>
//Klasa : Complex
class Complex {
public:
Complex (float real, float imag);
Complex add (Complex);
Complex sub (Complex);
float Re();
float Im();
void print();
friend istream & operator>> (istream &d, Complex &t);
friend ostream & operator<< (ostream &d, const Complex &t);
private:
float real, imag;
};
// definicija funkcija
Complex::Complex (float r, float i) {real=r; imag=i;}
Complex Complex::add (Complex c) {
return Complex(real+c.real, imag+c.imag);
}
Complex Complex::sub (Complex c) {
return Complex(real-c.real, imag-c.imag);
}
float Complex::Re() {return real;}
float Complex::Im() {return imag;}
void Complex:
rint() {
cout<<"real: "<<real<< "imag: "<< imag;
}
istream & operator>>(istream &d, Complex &t)
{ float re,im; d>>re>>im; return d;}
ostream & operator<<(ostream &d, const Complex &t)
{ return d<<"("<<t.real<<","<<t.imag<<")\n";}
// Glavni program
void main () {
Complex cx();
cin>>cx;
cout<<cx;
}
D:\MyProjects\kompleksni brojevi\kompleks.cpp(63) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class Complex (__cdecl *)(void)' (or there is no acceptable conversion)
i ovo pokazuje na liniju koda gde je 'cin'
Sta moze da bude?
include <iostream.h>
//Klasa : Complex
class Complex {
public:
Complex (float real, float imag);
Complex add (Complex);
Complex sub (Complex);
float Re();
float Im();
void print();
friend istream & operator>> (istream &d, Complex &t);
friend ostream & operator<< (ostream &d, const Complex &t);
private:
float real, imag;
};
// definicija funkcija
Complex::Complex (float r, float i) {real=r; imag=i;}
Complex Complex::add (Complex c) {
return Complex(real+c.real, imag+c.imag);
}
Complex Complex::sub (Complex c) {
return Complex(real-c.real, imag-c.imag);
}
float Complex::Re() {return real;}
float Complex::Im() {return imag;}
void Complex:
![Jezik :p :p](/styles/krstarica/xenforo/smilies/razz.gif)
cout<<"real: "<<real<< "imag: "<< imag;
}
istream & operator>>(istream &d, Complex &t)
{ float re,im; d>>re>>im; return d;}
ostream & operator<<(ostream &d, const Complex &t)
{ return d<<"("<<t.real<<","<<t.imag<<")\n";}
// Glavni program
void main () {
Complex cx();
cin>>cx;
cout<<cx;
}