#ifndef PRIORITY_QUEUE__
#define PRIORITY_QUEUE__
#include <queue>
template"<"class T, class S">"
class PriorityQueue{
public:
PriorityQueue();
void enqueue(T element);
T dequeue();
void makeheap();
bool isEmpty();
private:
priority_queue"<"T, vector"<"T">", S">" PQ;
};
#endif
I get the following errors:
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(16) : error C2143: syntax error : missing ';' before '<'
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(19) : see reference to class template instantiation 'PriorityQueue' being compiled
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(16) : error C2501: 'priority_queue' : missing storage-class or type specifiers
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(19) : see reference to class template instantiation 'PriorityQueue' being compiled
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(16) : error C2059: syntax error : '<'
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(19) : see reference to class template instantiation 'PriorityQueue' being compiled
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(18) : error C2238: unexpected token(s) preceding ';'
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(19) : see reference to class template instantiation 'PriorityQueue' being compiled
PQ.CPP
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(16) : error C2143: syntax error : missing ';' before '<'
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(19) : see reference to class template instantiation 'PriorityQueue' being compiled
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(16) : error C2501: 'priority_queue' : missing storage-class or type specifiers
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(19) : see reference to class template instantiation 'PriorityQueue' being compiled
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(16) : error C2059: syntax error : '<'
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(19) : see reference to class template instantiation 'PriorityQueue' being compiled
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(18) : error C2238: unexpected token(s) preceding ';'
d:\datastructure\ex2\ex2\ex2\priorityqueue.h(19) : see reference to class template instantiation 'PriorityQueue' being compiled
Error executing cl.exe.
ex2.exe - 8 error(s), 0 warning(s)
What is wrong?
And does the vector class is inside queue header?
[edited by - The C modest god on May 25, 2004 3:55:04 AM]
Help with compiler error...
I have the following code:
It could be an error in another file included before this one. And use > and < for > and <, respectively.
The only file that uses this file is:
#ifndef LIBRARY2_H__
#define LIBRARY2_H__
#include <iostream>
#include <string>
#include "PriorityQueue.h"
using namespace std;
/********************************************************************************/
/* The basic Event class
Pure virtual class
*/
class Event {
public:
Event (unsigned int _time = 0) : time(_time) { }
virtual ~Event() { }
// Return true if this event occurs earlier than the argument
virtual bool less(const Event& other) = 0;
// Return pointer to new event; 0 if no such event exists
virtual Event* process() = 0;
// Return a string representation of the event
virtual string toString() = 0;
// Return time of occurence
unsigned getTime() const { return time; }
protected:
const unsigned int time;
};
/* Comparison class for events
(Objects of this class are functors)
*/
struct EventComparison{
bool operator () (Event* first, Event* second){
return(second->less(*first));
}
};
/********************************************************************************/
/* The basic Simulation paradigm
Events are held in a priority queue, sorted according to their time
*/
class Simulation{
public:
// Construct a new simulation ending at end_time
Simulation(unsigned _end_time)
: eventQueue(), time(0), end_time(_end_time) { }
// Schedule an event
void schedule(Event* newEvent) { eventQueue.enqueue(newEvent); }
// Run the simulation
void run(){
eventQueue.makeheap();
while( !eventQueue.isEmpty() && (time < end_time)){
Event* current = eventQueue.dequeue();
time = current->getTime();
Event* next = current->process();
cout << "[Time: " << time << "] " << current->toString() << endl;
if(next) schedule(next);
delete(current);
}
while( !eventQueue.isEmpty() ) delete(eventQueue.dequeue());
}
private:
PriorityQueue<Event*, EventComparison> eventQueue;
unsigned int time;
const unsigned int end_time;
};
#endif
I have added the following code and it still does the missing ; before < error:
struct EventComparison2{
bool operator () (int first, int second){
return first;
}
};
priority_queue
<int,
vector<int>, EventComparison2> PQ;
You''re not using the std namespace in the header. Try prefixing std:: to the priority_queue and the vector in your PriorityQueue class declaration, so the private portion looks like:
- Neophyte
private:std::priority_queue<T,std::vector<T>,S> PQ;
- Neophyte
Thanks for the replies, I fixed the problem.
Just needed to add #include and using namespace std
Just needed to add #include and using namespace std
Sorry to go off topic, but your code looks like this to me:
quote:Original post by The C modest godThis is really annoying and really hard to read. You are supposed to put semicolons at the end of <, >, and every other character entity, for that matter. This is so that browsers can tell where the character entity ends instead of guessing (should &sigmaf be rendered as ς or σf?) Even better, just use GameDev''s [source] tag. Much easier on us all.#include <iostream>
#include <string>
...
time = current->getTime();
...
PriorityQueue<Event*, EventComparison> eventQueue;
Don''t put using in a header. Explicitly qualify in headers e.g. std::vector. It''s far more friendly; it doesn''t drag everything into the global namespace from the vector header. So if I''m using your header I don''t get problems with, for example, having my own variable called vector which is none of your business but you tromp on because you''ve put using namespace std; in your header.
Do what you want in your source file.
Do what you want in your source file.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement