operator <

I am trying to create a program that is an event simulation using the STL priority queue. I created the operator < function inside a struct, but when I run the program I get an error that I do not know how to make sense of. I have had a link error in the past (different project), but I was using different files and I was able to get rid of it by creating a new project with one file and then splitting up the client, implementation, and header file. However, this project is all in one file.

ERROR:

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "struct Event __cdecl processArrival(struct Event,class std::priority_queue<struct Event,class std::vector<struct Event,class std::allocator<struct Event> >,struct std::less<struct Event> >,class std::queue<struct Event,class std::deque<struct Event,class std::allocator<struct Event> > >)" (?processArrival@@YA?AUEvent@@U1@V?$priority_queue@UEvent@@V?$vector@UEvent@@V?$allocator@UEvent@@@std@@@std@@U?$less@UEvent@@@3@@std@@V?$queue@UEvent@@V?$deque@UEvent@@V?$allocator@UEvent@@@std@@@std@@@3@@Z) referenced in function "void __cdecl simulate(void)" (?simulate@@YAXXZ)


If I comment out the operator < function I'll get this error, which I think is because the priority queue by nature needs to have operator < implemented:

Severity Code Description Project File Line Suppression State
Error C2676 binary '<': 'const _Ty' does not define this operator or a conversion to a type acceptable to the predefined operator wk_11_sortedList_queues C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstddef 127

I posting just this because that is where the problem is, but if I need to post something else please let me know.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
  struct Event
{

	int customerID;
	int transactionTime;
	int arrivalTime;
	int currentTime;

	bool operator < (const Event& right) const
	{
		return this->arrivalTime < right.arrivalTime;

	}
};
Your error message complains about a "processArrival" function not being defined.
Last edited on
I have it defined, but it looks like I am not using one of the given parameters. For "processArrival" all I am supposed to do is store an arrival time, and a transaction time in a bankQueue which represents the people waiting in line at a bank. I used the first parameter "newEvent" which contains the top() values from from the event list, and the third parameter bankQueue so I can push the arrivalTime and transactionTime into it. I am not seeing what I should be doing with the second parameter "eventListPQueue" though. Also, I can't even debug what I have to check on values until I get past this error as the program will not compile to a breakpoint.

I'll post what I have.

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

#include <iostream>
#include <queue>
#include <fstream>
using namespace std;

class Customer
{
public:
	int customerID;
};


struct Event
{

	int customerID;
	int transactionTime;
	int arrivalTime;
	int currentTime;
	typedef int value_type;

	bool operator < (const Event& right) const
	{
		return this->arrivalTime < right.arrivalTime;

	}
};


void simulate();
Event processArrival(Event newEvent, priority_queue<Event> eventListPQueue, queue<Event> bankQueue);
Event processDeparture(Event newEvent, priority_queue<Event> eventListPQueue, queue<Event> bankQueue);

int main()
{
	simulate();
	return 0;
}





void simulate()
{
	ifstream file;
	int data;
	int newArrivalEvent = 0;
	int transactionTime = 0;
	bool tellerAvailable = true;

	
	/*Create an empty queue bankQueue to represent the bank line
	Create an empty priority queue eventListPQueue for the event list*/
	queue <Event> bankQueue;
	priority_queue <Event> eventListPQueue;

	// Create and add arrival events to event list  
	file.open("a11in1.txt");

	while (file) {                                     // data file is not empty

		file >> newArrivalEvent >> transactionTime;    // Get next arrival time aand transaction time t from file
		//cout << "test data: " << data << endl;
		cout << "test newArrivalEvent: " << newArrivalEvent << endl;
		cout << "test transactionTime: " << transactionTime << endl;

		// a new arrival event containing a and t
		Event event;
		event.arrivalTime = newArrivalEvent;
		event.transactionTime = transactionTime;
		eventListPQueue.push(event);	
	}
	file.close();
	
	
	
	// Event loop 
	int currentTime = 0;
	while (eventListPQueue.size() > 0 ) {                        // Event list is not empty

		Event newEvent;
		newEvent = eventListPQueue.top();
  
		currentTime = newEvent.arrivalTime;                      // Get current time       

		if (newEvent.arrivalTime)                                // is an arrival event
			processArrival(newEvent, eventListPQueue, bankQueue);

		else
			processDeparture(newEvent, eventListPQueue, bankQueue);

	}

	//****************  pseudiocode to fill in  **************************************

	//// Processes an arrival event. 
	//processArrival(arrivalEvent: Event, eventListPQueue : PriorityQueue, bankQueue : Queue) 
	//// Remove this event from the event list 
	//eventListPQueue.remove()    
	//
	//customer = customer referenced in arrivalEvent 
	//if (bankQueue.isEmpty() && tellerAvailable) {

	//	departureTime = currentTime + transaction time in arrivalEvent       
	//	newDepartureEvent = a new departure event with departureTime        
	//	eventListPQueue.add(newDepartureEvent)        
	//	tellerAvailable = false
	//}
	//else       
	//	bankQueue.enqueue(customer)
	//	
	//	// Processes a departure event . 
	//	+processDeparture(departureEvent: Event, eventListPQueue: PriorityQueue, bankQueue: Queue)

	//	// Remove this event from the event list 
	//	eventListPQueue.remove() 
	//	
	//	if (!bankQueue.isEmpty()) { 
	//		
	//		// Customer at front of line begins transaction 
	//		customer = bankQueue.peek()        
	//		bankQueue.dequeue()        
	//		departureTime = currentTime + transaction time in customer       
	//		newDepartureEvent = a new departure event with departureTime        
	//		eventListPQueue.add(newDepartureEvent)
	//	}
	//	else
	//		tellerAvailable = true

}





template<typename value_type>
Event processArrival(Event newEvent, priority_queue<value_type> eventListPQueue, queue<value_type> bankQueue)
{
	Event bankLine;
	bankLine.arrivalTime = newEvent;
	bankLine.transactionTime = newEvent;
	bankQueue.push(bankLine);

	return bankLine;
}

You have two functions:
1
2
3
Event processArrival( Event, priority_queue<Event>, queue<Event> ); // #1
template<typename value_type>
Event processArrival( Event, priority_queue<value_type>, queue<value_type> ); // #2 

The #1 is just a declaration for a normal standalone function. There is no implementation for it.

The #2 is a template. Furhermore, it not visible on line 89. The whole template has to be accessible when something needs to be instantiated from it. Before line 89.
Oh sorry. I was playing around with the typedef int value_type and forgot to change the parameters for consistency. I changed everything to <Event>.

Regarding, "The whole template has to be accessible when something needs to be instantiated from it." That reminds me. The only experience I have with templates is with a client, implementation, and header file. Then the implementation file would have to be removed from the project. This project is all in one file so I am not sure about how that works. I am not even sure if I should be using a template. If the STL priority queue is a templated class, does that mean I have to make my function a template?
If the STL priority queue is a templated class, does that mean I have to make my function a template?

No. The priority_queue<Event> is a concrete type. Not a template.

I did remove the declaration and moved your template to before the simulate(). The I got:
 In instantiation of 'Event processArrival(Event, std::priority_queue<value_type>,
  std::queue<value_type>) [with value_type = Event;
  typename std::vector<_Tp>::value_type = Event]':
1
2
3
4
5
6
7
8
9
10
11
template<typename value_type>
Event processArrival( Event newEvent,
   priority_queue<value_type> eventListPQueue,
   queue<value_type> bankQueue )
{
  Event bankLine;
  bankLine.arrivalTime = newEvent;// error: cannot convert 'Event' to 'int' in assignment
  bankLine.transactionTime = newEvent; // error: cannot convert 'Event' to 'int' in assignment
  bankQueue.push(bankLine);
  return bankLine;
}

That is not all that is odd in this function:
* You push an Event to bankQueue that holds value_type objects
* eventListPQueue is not used
* You push to bankQueue that is a local copy (it is a by value parameter)
* You set a value to only two members of bankLine.
Topic archived. No new replies allowed.