class student
{
private:
string imie;
string nazwisko;
long nr_indeks;
public:
long index();
student();
student(string imie,string nazwisko,long nr_indeks);
friend ostream& operator<< (ostream& stream, student& st);
friend bool operator==(long &indeks, student &st);
friend istream& operator >> (istream& stream, student &st);
};
ostream& operator<<(ostream& stream, student& st) {
stream << st.imie << " " << st.nazwisko << " " << st.nr_indeks<<endl;
return stream;
}
bool operator==(long & indeks, student & st)
{
if (indeks == st.index()) {
return true;
}
else return false;
}
istream & operator >> (istream & stream, student & st)
{
stream >> st.imie >> st.nazwisko >> st.nr_indeks;
return stream;
}
long student::index()
{
return nr_indeks;
}
student::student(){
imie = "Panx";
nazwisko="Ixinski";
nr_indeks = 0;
}
student::student(string imie, string nazwisko, long nr_indeks) :
imie(imie), nazwisko(nazwisko), nr_indeks(nr_indeks) { }
int main(){
student b;// działa
student b();// nie działa i nie wiem dlaczego
cin >> b;
}
Nie rozumiem dlaczego gdy piszę student b() to wtedy mam błąd "no operator ">>" matches these operands" a jak piszę student b; to wtedy wszystko działa. Czym się różnią te zapisy?
Czy to dlatego że nie dałoby się odróżnić tej definicji zmiennej od deklaracji funkcji bezparametrowej? i ja zapisałem to niejednoznacznie?