No operator "<<" matches these operands

Hey guys and gals, I posted earlier regarding problems with my program being split into 3 files; a header, implementation and main. As my title says, I get that error in the main.cpp file. Any workarounds for this?

Header file:

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
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;

class Employee
{
	// Private members.
	private:
		string name,
			   department,
			   position;
		int idNumber;
	
	// Public members.
	public:
		Employee(); // Default constructor.
		Employee(string EmpName, int idNum, int EmpID, string Dept, string Position)
		Employee(string EmpName, int idNum);
		Employee(string EmpName, int idNum, string Dept, string Pos); 
		
		void setName (string EmpName);
		void setIDNum (int idNum);
		void setDesc (string Dept);
		void setPos (string Pos);

		void getName(); 	
		void getIDNum(); 	
		void getDept();  	
		void getPos(); 		
};
#endif 


Implementation file:
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
#include "Employee.h"

// Default constructor.
Employee::Employee()
{
	name = " ";
	idNumber = 0;
	department = " ";
	position = " ";
}

// Constructor 1 with arguments as parameters.
Employee::Employee (string EmpName, int idNum, int EmpID, string Dept, string Position)
{
	name = EmpName;
	idNumber = idNum;
	department = Dept;
	position = Position;
	EmpID = idNumber;
}

// Constructor 2 with arguments as parameters.
Employee::Employee (string EmpName, int idNum, string Dept, string Pos)
{
	name = EmpName;
	idNumber = idNum;
	department = Dept;
	position = Pos;
}

// Mutator function for name.
void Employee::setName (string EmpName)
{
	name = EmpName;
}

// Mutator function for idNum.
void Employee::setIDNum (int idNum)
{
	idNumber = idNum;
}

// Mutator function for department.
void Employee::setDesc (string Desc)
{
		department = Desc;
}

// Mutator function for position.
void Employee::setPos (string Pos)
{
		position = Pos;
}


main file:

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
#include "Employee.h"
#include <iostream>
using namespace std;

int main(void)
{
	// Three employee objects called e1, e2, e3
	Employee e1 ("Susan Meyers", 47899,
		"Accounting", "Vice President");

	Employee e2 ("Mark Jones", 39119,
		"IT", "Programmer");

	Employee e3 ("Joy Rodgers", 81774,
		"Manufacturing", "Engineer");

	// Display the data in table format.
	cout << "Name: \t \t ID Number: \t Department: \t Position:" << endl;

	cout << e1.getName() << "\t" << e1.getIDNum() << "\t\t"
		 << e1.getDept() << "\t" << e1.getPos() << endl;

	cout << e2.getName() << "\t" << e2.getIDNum() << "\t\t"
		 << e2.getDept() << "\t" << e2.getPos() << endl;

	cout << e3.getName() << "\t" << e3.getIDNum() << "\t\t"
		 << e3.getDept() << "\t" << e3.getPos() << endl;
}
Where are the definitions for the get functions in Employee.h?
What do you mean? Aren't these the definitions?
1
2
3
4
void getName(); 	
void getIDNum(); 	
void getDept();  	
void getPos(); 
Those are declarations. Definitions of functions include the bodies.

Functions that return type void don't actually return anything, which certainly seems suspect given the names and that you're attempting to use them as if they do return something.
No, those are declarations. I meant the definitions in Employee.cpp. Everything looks good in the header, but you don't define the getter functions like you did the setters. Definitions are what you have in Employee.cpp. A declaration, or what is also called a prototype, declare the functions return type, name and parameters followed by a semicolon. Without definitions the getters do nothing. All you have to do for the getters is return the data member for that each function is named after, that way it's passed to cout.
So..like {return name;} or something in that matter?
Yup, that's all getters usually do. Since the data members are private you use getters to "get" the data from the object.
Got cha. I'll try that in a bit.
Topic archived. No new replies allowed.