Weird compilation error

G++ has been kind of trolling me with this huge error report. But I'm totally unable to exatract any information out of it. It would be gread if you could help me.

The error report:
 
http://pastebin.com/aQpc4hFs 


The code itself:

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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

#include <iostream>

#include "Calendar.h"
#include "Transaction.h"

using namespace std;

int main() {
	
	Calendar *calendar = new Calendar();
	calendar->init(0, 300);
	calendar->push(0,1, new Transaction(calendar));
	calendar->run();
}

----------CALENDAR.H----------

#include <iostream>
#include <queue>

using namespace std;

class Transaction;

struct activationRecord {

	double time;
	int priority;
	Transaction *transaction;
};

class Calendar {

	private:
		double timeStop;
		double time;
		priority_queue<activationRecord> activationCalendar;

	public:
		bool isEmpty();
		void push(double, int, Transaction*);
		void pop();
		void run();
		void init(double, double);

		double getTime();

		activationRecord top();
};

----------CALENDAR.CPP----------

#include <iostream>

#include "Calendar.h"
#include "Transaction.h"

using namespace std;

bool Calendar::isEmpty() {

	return activationCalendar.empty();
}

void Calendar::pop() {

	activationCalendar.pop();
}

void Calendar::push(double t, int p, Transaction *tr) {

	activationRecord r;

	r.priority = p;
	r.time = t;
	r.transaction = tr;

	activationCalendar.push(r);
}

activationRecord Calendar::top() {

	return activationCalendar.top();
}

void Calendar::run() {
	
	activationRecord r;


	while(!activationCalendar.empty()) {


		r = activationCalendar.top();
		activationCalendar.pop();


		if(r.time > timeStop) {
			time = timeStop;
			break;
		}

		//Posun cas na cas aktualniho eventu
		time = r.time;

		cout << "Time: " << time << " ";

		//Vykonej event
		(*r.transaction).choose();
	}
}


void Calendar::init(double start, double stop) {

	 time = start;
	 timeStop = stop;
}

double Calendar::getTime() {

	return time;
}


bool operator <(const activationRecord & a, const activationRecord & b)
{
    return a.time > b.time;
}

----------TRANSACTION.H----------

#include <iostream>

using namespace std;

class Calendar;

class Transaction {

	private:
		int chooser;
		Calendar *cal;

	public:
		Transaction(Calendar*);
		~Transaction();

		void choose();
		void event1();
		void event2();
		void event3();
		void event4();
};
----------TRANSACTION.CPP----------

#include <iostream>

#include "Transaction.h"
#include "Calendar.h"

using namespace std;


Transaction::Transaction(Calendar *c) {

	this->cal = c;
	this->chooser = 1;
}

void Transaction::choose() {

	switch(chooser){
		case(1):
			event1();
			break;
		case(2):
			event2();
			break;
		case(3):
			event3();
			break;
		case(4):
			event4();
			break;
	}
}


void Transaction::event1() {

	cout << "Event1::Transakce" << this << endl;

	chooser = 2;


	cal->push(cal->getTime()+200, 1, new Transaction(cal));


	cal->push(cal->getTime(), 1, this);
}

void Transaction::event2() {

	cout << "Event2::Transakce" << this << endl;

	chooser = 3;

	cal->push(cal->getTime()+50, 1, this);
}

void Transaction::event3() {

	cout << "Event3::Transakce" << this << endl;

	chooser = 4;

	cal->push(cal->getTime(), 1, this);

}

void Transaction::event4() {

	cout << "Event4::Transakce" << this << endl;

}


Ty for any help
make 2>&1 | grep error
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: error: no match for ‘operator<’ (operand types are ‘const activationRecord’ and ‘const activationRecord’)


main.cpp ignores the existence of the bool operator <(const activationRecord & a, const activationRecord & b) function.
Declare it in a header file.

Also, use header guards http://www.cplusplus.com/forum/articles/10627/
Don't using in headers
And stop leaking memory.
Last edited on
Thank you for you reply ne555,

problem is when I try to declare it in as private method of Calendar in Calendar.h (like this)

 
bool operator < (const activationRecord, const activationRecord);


I get this error

 
binary 'operator <' has too many parameters


Any ideas?
You define it as a global function, declare it as a global function.


> when I try to declare it in as private method of Calendar
If it is private nobody could access it
If it is a method then the prototype should be bool operator < (const activationRecord) const; (remember that the calling object is passed as this)
If the function refers to `activationRecord' objects, then it should be a member of `activationRecord' no of `Calendar'
I followed you advice which seems reasonable to me. It led to huge decrease of errors I got, nevertheless there is still a report I can't resolve.

I tried defining the operator method like this:

1
2
3
bool activationRecord::operator <(const activationRecord & a, const activationRecord & b) {
return a.time > b.time;
}


Btw. It's declaration

1
2
3
4
5
6
7
struct activationRecord {

	double time;
	int priority;
	Transaction *transaction;
	bool operator < (const activationRecord) const;
};

The new, only one row error I'm getting is obvisouly this:

1
2
Calendar.cpp:84:89: error: ‘bool activationRecord::operator<(const activationRecord&, const activationRecord&)’ must take exactly one argument
make: *** [Calendar.o] Error 1


And one more thing I don't understand. You mentioned I should not use "using namespace std;" in header file. But I kind on need it there, because I cant define a priority queue there otherwise. Am I getting it wrong.

Thank You,

you've been very helpful.
Last edited on
¿why is your definition different than your declaration?
I don't realize how the compiler could make it clearer: `must take exactly one argument'
1
2
3
4
5
6
7
8
9
10
11
struct activationRecord {

	double time;
	int priority;
	Transaction *transaction;
	bool operator < (const activationRecord &) const; //declaration (one argument)
};

bool activationRecord::operator <(const activationRecord & b) const{ //definition (one argument)
   return this->time > b.time;
}



> I should not use "using namespace std;" in header file.
> But I kind on need it there, because I cant define a priority queue there otherwise.
std::priority_queue
Im so stupid, thank You so much. I just couldnt solve how to define the operator using just one parameter, i didn't make sense to me. Now I got it.
Topic archived. No new replies allowed.