Don't know what these compilation errors mean?

Hello. I have some .cpp and .h files in a project that I built with codeblocks and when I compile I get these errors. I don't know what they mean:
1
2
3
4
5
6
7
8
9
||=== registration, Debug ===|
C:\Users\John\Documents\opover_registration\enrollment.cpp|46|error: no matching function for call to 'Course::Course(std::string&)'|
C:\Users\John\Documents\opover_registration\enrollment.cpp|69|error: no match for 'operator<<' in 'reportFile << *(courses + ((sizetype)(((unsigned int)i) * 12u)))'|
C:\Users\John\Documents\opover_registration\arrayUtils.h|56|error: no match for 'operator<' in 'value < *(array + ((sizetype)(((unsigned int)toBeMoved) * 12u)))'|
C:\Users\John\Documents\opover_registration\arrayUtils.h|89|error: no match for 'operator<' in '*(list + ((sizetype)(((unsigned int)loc) * 12u))) < searchItem'|
C:\Users\John\Documents\opover_registration\arrayUtils.h|93|error: no match for 'operator==' in '*(list + ((sizetype)(((unsigned int)loc) * 12u))) == searchItem'|


||=== Build finished: 5 errors, 5 warnings (0 minutes, 5 seconds) ===|


The errors seem to be coming from this file:

enrollment.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
#include "enrollment.h"
#include <iostream>
#include <string>
#include "course.h"
#include "arrayUtils.h"


using namespace std;





/*
 * Read the course names and max enrollments. Keep the courses
 * in alphabetic order by course name.
 */
void readCourses (istream& courseFile, int numCourses, 
		  Course* courses)
{
  for (int i = 0; i < numCourses; )
    {
      Course course;
      course.enrollment = 0;
      courseFile >> course.name >> course.maxEnrollment;
      addInOrder (courses, i, course);
    }
}

/*
 * Read the enrollment requests, processing each one and tracking
 * the number of students successfully enrolled into each course.
 */
void processEnrollmentRequests (istream& enrollmentRequestsFile, 
				int numCourses, 
				Course* courses)
{
  // Read the requests, one at a time, serving each one
  string courseName;
  enrollmentRequestsFile >> courseName;
  while (enrollmentRequestsFile) {
    enrollmentRequestsFile >> ws;
    string studentName;
    getline (enrollmentRequestsFile, studentName);

    Course searchFor (courseName);
    int pos = seqOrderedSearch (courses, numCourses, searchFor);
    if (pos >= 0 && courses[pos].enrollment < courses[pos].maxEnrollment)
      {
	cout << studentName << " has enrolled in " << courseName << endl;
	++courses[pos].enrollment;
      }
    else
      cout << studentName << " cannot be enrolled in " << courseName << endl;

    enrollmentRequestsFile >> courseName;
  }
}

/*
 * Write a CSV report listing each course and its enrollment.
 */
void generateReport (ostream& reportFile, 
		     int numCourses, 
		     Course* courses)
{
  for (int i = 0; i < numCourses; ++i)
    {
      reportFile << courses[i] << endl;
    }
}




void processEnrollments (istream& courseFile, istream& enrollmentRequestsFile,
			 ostream& reportFile)
{
  int numCourses;
  courseFile >> numCourses;

  Course* courses = new Course[numCourses];

  readCourses (courseFile, numCourses, courses);
  processEnrollmentRequests (enrollmentRequestsFile, numCourses, 
			     courses);
  generateReport (reportFile, numCourses, courses);
}


Here is the related arrayUtils 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef ARRAYUTILS_H
#define ARRAYUTILS_H



//  Add to the end
//  - Assumes that we have a separate integer (size) indicating how
//     many elements are in the array
//  - and that the "true" size of the array is at least one larger 
//      than the current value of that counter
template <typename T>
void addToEnd (T* array, int& size, T value)
{
   array[size] = value;
   ++size;
}



// Add value into array[index], shifting all elements already in positions
//    index..size-1 up one, to make room.
//  - Assumes that we have a separate integer (size) indicating how
//     many elements are in the array
//  - and that the "true" size of the array is at least one larger 
//      than the current value of that counter

template <typename T>
void addElement (T* array, int& size, int index, T value)
{
  // Make room for the insertion
  int toBeMoved = size - 1;
  while (toBeMoved >= index) {
    array[toBeMoved+1] = array[toBeMoved];
    --toBeMoved;
  }
  // Insert the new value
  array[index] = value;
  ++size;
}


// Assume the elements of the array are already in order
// Find the position where value could be added to keep
//    everything in order, and insert it there.
// Return the position where it was inserted
//  - Assumes that we have a separate integer (size) indicating how
//     many elements are in the array
//  - and that the "true" size of the array is at least one larger 
//      than the current value of that counter

template <typename T>
int addInOrder (T* array, int& size, T value)
{
  // Make room for the insertion
  int toBeMoved = size - 1;
  while (toBeMoved >= 0 && value < array[toBeMoved]) {
    array[toBeMoved+1] = array[toBeMoved];
    --toBeMoved;
  }
  // Insert the new value
  array[toBeMoved+1] = value;
  ++size;
  return toBeMoved+1;
}


// Search an array for a given value, returning the index where 
//    found or -1 if not found.
template <typename T>
int seqSearch(const T list[], int listLength, T searchItem)
{
    int loc;

    for (loc = 0; loc < listLength; loc++)
        if (list[loc] == searchItem)
            return loc;

    return -1;
}


// Search an ordered array for a given value, returning the index where 
//    found or -1 if not found.
template <typename T>
int seqOrderedSearch(const T list[], int listLength, T searchItem)
{
    int loc = 0;

    while (loc < listLength && list[loc] < searchItem)
      {
       ++loc;
      }
    if (loc < listLength && list[loc] == searchItem)
       return loc;
    else
       return -1;
}


// Removes an element from the indicated position in the array, moving
// all elements in higher positions down one to fill in the gap.
template <typename T>
void removeElement (T* array, int& size, int index)
{
  int toBeMoved = index + 1;
  while (toBeMoved < size) {
    array[toBeMoved] = array[toBeMoved+1];
    ++toBeMoved;
  }
  --size;
}



// Search an ordered array for a given value, returning the index where 
//    found or -1 if not found.
template <typename T>
int binarySearch(const T list[], int listLength, T searchItem)
{
    int first = 0;
    int last = listLength - 1;
    int mid;

    bool found = false;

    while (first <= last && !found)
    {
        mid = (first + last) / 2;

        if (list[mid] == searchItem)
            found = true;
        else 
            if (searchItem < list[mid])
                last = mid - 1;
            else
                first = mid + 1;
    }

    if (found) 
        return mid;
    else
        return -1;
}





#endif 



The goal is to leave the above files unchanged and do my own implementations in a course .cpp/.h file pair. I have a struct:

struct Course {
std::string name;
int maxEnrollment;
int enrollment;
};
The error messages are clear enough. Why do not you read them? For example the first message says that there is no such constructor as

Course::Course(std::string&);

but you are tryig to call it

Course searchFor (courseName);



Last edited on
It looks like that you are too clever that you need no help from experienced programmers.

EDIT: I see that you deleted your previous message. :)
Well, then look what constructors class Course has and where constructor

Course::Course(std::string&);

is declared and defined which you call in statement

Course searchFor (courseName);
Last edited on
So when I put that constructor in my course.h file I get these errors:

1
2
3
4
C:\Users\John\Desktop\opover_registration\course.h|11|error: prototype for 'Course::Course(std::string&)' does not match any in class 'Course'|
C:\Users\John\Desktop\opover_registration\course.h|6|error: candidates are: Course::Course(const Course&)|
C:\Users\John\Desktop\opover_registration\course.h|6|error:                 Course::Course()|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===|


Why is it looking for a class when I'm using a struct? Do I also need to declare a class?
class is a general term used to denote structures and classes and even unions. In the C++ standard class-key is defined as

class-key:
class
struct
union

More usually word class is used to denote only structures and classes that is user defined types that were declared either with keyword class or keyword struct.

As for your first question then show how you put this constructor in your class definition.
Well I want to use it as

Course course;
Course::course(std::string& courseName);

But I get the error below:

C:\Users\John\Documents\opover_registration\course.h|11|error: expected constructor, destructor, or type conversion before ';' token|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|

Am I missing a step? Thought what I wrote above was a constructor.
I do not understand such code

Course course;
Course::course(std::string& courseName);

Please show the class definition.
Well if I understand you correctly you said a class can be a struct? Then here is my definition:

struct Course {
std::string name;
int maxEnrollment;
int enrollment;
};
And where do you see any constructor declared in the class?
Also on a side note, when you have a class that takes 1 parameter for the constructor you should declare it as myClass myInstance = myClass(var) and the definition uses the explicit keyword to avoid confusion with the compiler thinking it's a method prototype.
I don't see the constructor in the class. But I'm guessing I need to use one because I cannot change the code in enrollment.cpp . I shouldn't have to (and prefer not to) change the struct either but it is legal . So I guess I can declare a constructor:

Course::Course(name) const;

like so? I get an error that says C:\Users\John\Documents\opover_registration\course.h|14|error: expected constructor, destructor, or type conversion before '(' token|

But since the original error was saying I didn't declare with a string type I wrote:

Course::Course string(name) const;

the above error asked for type conversion before the '(' so i put string before it. Now it says: C:\Users\John\Documents\opover_registration\course.h|14|error: 'Course::Course' names the constructor, not the type|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|

I'm so confused . I guess my problem is how to declare and then implement .
Last edited on
All class member functions including constructors shall be declared inside the class definition. So if you may not change the class definition then you can not declare the constructor.
So I have to put this line: Course::Course(std::string&);

inside the struct in order for me to able to use the constructor then? No other way without changing the enrollment.cpp ?
Hey man,
Our assignment is focused on overloading the operators "<<"," <", and "==". Yes it is true that we need to create a constructor that accepts a string type as a parameter. Do this by adding

Course(std::string&);

to our course header file. Now in course.cpp implement the Course constructor.

1
2
3
4
Course::Course(std::string& variableName)
{
    //your code here
}


To figure out what is done in this function, look at what parameters the function accepts and what variables were originally in the struct given to us that the parameter could be assigned to.

Now that we figured out the constructor, focus on overloading the operators. Do this by looking at what they are comparing in the errors. (hover over them to see the two values and determine what your overload functions should compare.) if you need help I'll be in the CS lab all today pretty much (assuming that you attend ODU). Just look for the guy with the big ass Alienware.
Best of Luck,
-England
Well that got me started. Thank you everyone.
Topic archived. No new replies allowed.