Hello!
I'm trying to overload the << operator but it just won't work
my code is the following:
the compiler tells me the following error message:
"student.h" : E2080 'student::opera tor <<(ostream &,const student &)' must be declared with one parameter at line 18
I'm trying to overload the << operator but it just won't work
my code is the following:
Code:
the student.h file #include <string> #include <iostream> using namespace std; class student { private: string name; string department; public: student(string n = "", string dep = 0) : name(n), department(dep) {} string get_name() const { return name; } string get_department () const { return department; } void set_name(const string& n) { name=n; } void set_department (const string& d) {department=d;} ostream& operator << (ostream& os, const student& s); };
Code:
the student.cpp file ostream& student::operator << (ostream& os, const student& s) { return os<<s.get_name()<<'\t'<<s.get_department()<<endl; }
Code:
main.cpp file #include "student.h" int main() { student st("Bill Jones", "Zoology"); cout<<st; }
"student.h" : E2080 'student::opera tor <<(ostream &,const student &)' must be declared with one parameter at line 18
Comment