error: no match for 'operator<<'

This is my code


Project.h
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
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef PROJECT_H
#define PROJECT_H

#include <iostream>
#include <string>
#include "staff.h"

class Division;


class Project {
public:

  typedef const Staff* iterator;

  Project(int maxStaff = DEFAULT_MAXSTAFF);


  // Attributes of Project

  // Project title
  std::string getTitle() const     {return theTitle;}
  void setTitle(std::string title) {theTitle = title;}

  // To which division does this project belong? Each project belongs
  // to one division, but a division may have many projects.
  Division* getDivision() const    {return theDivision;}
  void setDivision(Division* publ)  {theDivision = publ;}

  // The project ID is a unique identifier for the project.
  std::string getProjectID() const     {return theProjectID;}
  void setProjectID(std::string projectID)  {theProjectID = projectID;}

  // Budget codes indicate to whome this project is charged.
  std::string getBudgetCode() const    {return theBudgetCode;}
  void setBudgetCode(std::string projectID) {theBudgetCode = projectID;}


  // Operations on Project

  // Add a staff member to the project. Staff should be kept in alphabetic
  // order by name.
  void addStaff(const Staff&);
  int numberOfStaff() const;

  // Access to list of staff assigned to this project
  iterator begin() const;
  iterator end() const;


  bool operator< (const Project& bk) const;

private:
  std::string theTitle;
  std::string theProjectID;
  std::string theBudgetCode;
  Division* theDivision;

  int numStaff;
  int theMaxStaff;
  Staff* staff;  // array of Staff

  static const int DEFAULT_MAXSTAFF = 12;
};


#endif 




division.cpp
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
56
57
58
59
60
61
62
63
64
#include "division.h"
#include "project.h"
#include "split.h"

using namespace std;


Division::Division() {}


void Division::addProject(Project b)
{
  activeProjects.push_back (b);
}


int Division::numberOfProjects() const
{
  return activeProjects.size();
}


  
istream& operator>> (istream& in, Division& p)
{
  string line;
  if (in)
    {
      getline(in, line);
    }

  string fields[4];
  int fieldCount = split(line, "\t", fields, 4);

  p = Division();
  p.putName (fields[0]);
  p.putRoom (fields[1]);
  p.putBuilding (fields[2]);
  p.putDivisionCode (fields[3]);
}
      

std::ostream& operator<< (std::ostream& out, const Division& div)
{
  out << div.getName() << "\t"
      << div.getDivisionCode() << "\t"
      << div.getBuilding() << ":" << div.getRoom()
      << "\n";
  if (div.numberOfProjects() > 0)
    {
      int i = 0;
      for (Division::const_iterator p = div.begin();
	   p != div.end(); ++p)
	{
	  ++i;
	  out << i << "/" << div.numberOfProjects() << ": ";
	  out << *p << "\n";
	}
    }
  else
    out << "(no projects)\n";
  return out;
}


And this is the error

On line 57 of division.cpp
'error: no match for 'operator<<' in out (&p)->std::_List_const_iterator<_Tp>::operator* [with _Tp = Project]()'|




I'm supposed to only edit the Project.h file for this problem. I'm sure its something to do with changing the operator but I can't seem to figure this out :l

Any help would be greatly appreciated and also, if you solve my problem, could you please explain to me what you did and why so I understand what I didn't before. Thanks for your help.
Declare operator<< in the header file.
Maybe I didn't specify, and for that I apologize. I continue to try to do that but I can't seem to do it properly.
Since I don't see it, what does div.begin() return.
complete divistion.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "division.h"
#include "project.h"
#include "split.h"

using namespace std;


Division::Division() {}


void Division::addProject(Project b)
{
  activeProjects.push_back (b);
}


int Division::numberOfProjects() const
{
  return activeProjects.size();
}


  
istream& operator>> (istream& in, Division& p)
{
  string line;
  if (in)
    {
      getline(in, line);
    }

  string fields[4];
  int fieldCount = split(line, "\t", fields, 4);

  p = Division();
  p.putName (fields[0]);
  p.putRoom (fields[1]);
  p.putBuilding (fields[2]);
  p.putDivisionCode (fields[3]);
}
      

std::ostream& operator<< (std::ostream& out, const Division& div)
{
  out << div.getName() << "\t"
      << div.getDivisionCode() << "\t"
      << div.getBuilding() << ":" << div.getRoom()
      << "\n";
  if (div.numberOfProjects() > 0)
    {
      int i = 0;
      for (Division::const_iterator p = div.begin();
	   p != div.end(); ++p)
	{
	  ++i;
	  out << i << "/" << div.numberOfProjects() << ": ";
	  out << *p << "\n";
	}
    }
  else
    out << "(no projects)\n";
  return out;
}






Division::iterator Division::begin()
{
  return activeProjects.begin();
}

Division::const_iterator Division::begin() const
{
  return activeProjects.begin();
}

Division::iterator Division::end()
{
  return activeProjects.end();
}

Division::const_iterator Division::end() const
{
  return activeProjects.end();
}

bool Division::operator< (const Division& right) const
{
  return theName < right.theName
    || (theName == right.theName &&
	theDivisionCode < right.theDivisionCode);
}




division.h
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
56
#ifndef DIVISION_H
#define DIVISION_H

#include <iostream>
#include <string>
#include <list>

#include "project.h"


class Division {
public:
  Division();

  std::string getName() const {return theName;}
  void putName(std::string name) {theName = name;}

  std::string getRoom() const {return theRoom;}
  void putRoom(std::string room) {theRoom = room;}

  std::string getBuilding() const {return theBuilding;}
  void putBuilding(std::string building) {theBuilding = building;}

  std::string getDivisionCode() const {return theDivisionCode;}
  void putDivisionCode(std::string divisionCode) {theDivisionCode = divisionCode;}

  void addProject(Project);
  int numberOfProjects() const;

  typedef std::list<Project> ProjectSequence;
  typedef ProjectSequence::iterator iterator;
  typedef ProjectSequence::const_iterator const_iterator;

  iterator begin();
  iterator end();

  const_iterator begin() const;
  const_iterator end() const;

  bool operator< (const Division& right) const;

private:
  std::string theName;
  std::string theRoom;
  std::string theBuilding;
  std::string theDivisionCode;

  std::list<Project> activeProjects;
};


std::istream& operator>> (std::istream& in, Division& div);
std::ostream& operator<< (std::ostream& out, const Division& div);


#endif 




I thought I included the whole file but I must not have copied correctly. I have a few more files I can include if need be. The only other one that might be helpful would be division.h which I included above
Thanks now it makes sense
'error: no match for 'operator<<' in out (&p)->std::_List_const_iterator<_Tp>::operator* [with _Tp = Project]()'|


See the list iterator part?

std::list<Project> begin() This is what begin returns.

1
2
3
4
5
6
7
for (Division::const_iterator p = div.begin(); p != div.end(); ++p)
{
   ++i;
   out << i << "/" << div.numberOfProjects() << ": ";
   //What is your intention with this statement, I think you think this is a Division...
   out << *p << "\n";  //It's actually Project, which you have not overloaded the << operator for..
}
I am currently not at my laptop to check it but Im fairly certain when I attempted to overload the operator, the original error disappeared but I received an error saying I was not able to overload it. I'll have to double check though to give you the exact error
As I expected, I get this error.

|53|error: `bool Project::operator<<(const Project&) const' and `bool Project::operator<<(const Project&) const' cannot be overloaded|

Firstly don't overload the operator for your class. Make it a non-const non-member function like you did for Division.
Okay, thats helpful. Thank you. Now, I think I'm headed in the correct direction but ran across another error.

project.cpp
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
#include "division.h"
#include "project.h"

#include <algorithm>
#include <cassert>
#include <cstdlib>

using namespace std;

Project::Project(int maxStaff)
  : theProjectID(""), theBudgetCode(""), theDivision(0), numStaff(0),
    theMaxStaff(maxStaff)
{
  staff = new Staff[maxStaff];
}

Project::iterator Project::begin() const
{
  return staff;
}


Project::iterator Project::end() const
{
  return staff + numStaff;
}






/**** insert your operations for Projects here  ***/


std::ostream& operator<< (std::ostream& out, Project::const_iterator p)
{
    out << p.getTitle << "\t"
	      << p.getDivision << "\t"
	      << p.getProjectID << "\t"
	      << p.getBudgetCode << "\t"
	      << "\n";
	  return out;
}



I put the operator in project.cpp and it looks like this (, starting on line 36).

I get these errors:

Z:\CS330\Assignment 1\project.cpp|36|error: 'Project::const_iterator' has not been declared|
Z:\CS330\Assignment 1\project.cpp||In function 'std::ostream& operator<<(std::ostream&, int)':|
Z:\CS330\Assignment 1\project.cpp|38|error: request for member 'getTitle' in 'p', which is of non-class type 'int'|
Z:\CS330\Assignment 1\project.cpp|39|error: request for member 'getDivision' in 'p', which is of non-class type 'int'|
Z:\CS330\Assignment 1\project.cpp|40|error: request for member 'getProjectID' in 'p', which is of non-class type 'int'|
Z:\CS330\Assignment 1\project.cpp|41|error: request for member 'getBudgetCode' in 'p', which is of non-class type 'int'|
||=== Build finished: 5 errors, 0 warnings ===|



Before I have it the way I posted, the operator functions p.getTitle, p.getDivision and such all had () at the end of them but that did not fix it.

ex: p.getTitle() << .......


Any more guidance? Thank you guys for helping me. You are a godsend.
Topic archived. No new replies allowed.