where's the error?

the code;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

class human{
	string name;
	
	public:
	human(string name): name(name)
		{cout << "A Human is created: NAME = " << name << endl;}
	string getName(){return name;}
};

class student: virtual public human{
	int id;
	
	public:
	student(string name, int id): human(name), id(id)
		{cout << "A Student is created: NAME = " << getName() << " ID = " << id << endl;}
	int getid(){return id;}
};

class employee: virtual public human{
	double salary;
	
	public:
	employee(string name, double salary): human(name), salary(salary)
		{cout << "An Employee is created: NAME = "
		<< getName() << " SALARY = " << salary << endl;}
	double getsalary(){return salary;}
};

class workingstudent: public student, public employee{
	public:
	workingstudent (string name, int id, double salary):
	human(name), student(name, id), employee(name, salary)
	{	cout << "A working student is created: Name = " << student::getName()
		<< ". Id = " << getid() << ". Salary" << getsalary() << endl;}
	void print()
	{cout << "Name = " << getName() << ". Id = " << getid() 
         << ". Salary = " << getsalary() << endl;}
};

int main() {
  human h("Michael");
  student* s = new student("Kelly", 111);
  employee e("Dennis", 50000);
  workingstudent w("john", 222, 90000009);
  cout << h.getName() << endl
       << s->getName() << " " << s->getid()<< endl
	   << e.getName() << " " << e.getsalary() << endl
	   << w.print();
  delete s;
}


when i ran the code, it gave me the error

b.cpp: In function 'int main()':
b.cpp:53:16: error: no match for 'operator<<' in '((std::basic_ostream<char>::__
ostream_type*)((std::basic_ostream<char>*)std::operator<< [with _Traits = std::c
har_traits<char>](((std::basic_ostream<char>&)((std::basic_ostream<char>*)std::o
perator<< [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::a
llocator<char>](((std::basic_ostream<char>&)((std::basic_ostream<char>::__ostrea

and then it goes on and on.. what is the error at line 53?
Why are you trying to cout the return value of a function that does not return a value?
what do you mean? the function to return a value is all declared and defined in the parent class.
im not using the void function to return a value, merely to print out the return value that was gotten from the parent class.
1) workingstudent w;
2) void w::print();
3) << w.print();
4) You try to insert into stream 'void'
5) you should write adequate 'operator<<' (http://www.cplusplus.com/reference/iostream/ostream/operator%3C%3C/ )

link fixed
Last edited on
link is not working
i still dont get it :(

can someone just show me what i should change in order to make it work?
Change:
52
53
	   << e.getName() << " " << e.getsalary() << endl
	   << w.print();
to:
52
53
	   << e.getName() << " " << e.getsalary() << endl;
	      w.print();


You declare the print function to return void, meaning nothing. You can't cout void! And the function does the couting for you.
Last edited on
you do not require insertion function for print() function,

1
2
3
4
5
workingstudent w("john", 222, 90000009);
  cout << h.getName() << endl;
   cout<< s->getName() << " " << s->getid()<< endl;
  cout << e.getName() << " " << e.getsalary() << endl;
	  w.print();
oh my god you're right! wow thank you thank you, i wont make this mistake again.
Topic archived. No new replies allowed.