I'm trying to overload the << operator but it just won't work
my code is the following:
Expand|Select|Wrap|Line Numbers
- 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);
- };
Expand|Select|Wrap|Line Numbers
- the student.cpp file
- ostream& student::operator << (ostream& os, const student& s)
- {
- return os<<s.get_name()<<'\t'<<s.get_department()<<endl;
- }
Expand|Select|Wrap|Line Numbers
- main.cpp file
- #include "student.h"
- int main()
- {
- student st("Bill Jones", "Zoology");
- cout<<st;
- }
"student.h": E2080 'student::operator <<(ostream &,const student &)' must be declared with one parameter at line 18