473,549 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Little problem to use a priority queue

Hello,

I managed to implement the AStar algorithm, however I have some trouble
using the priority queue, and the 'compare' function.
Here is my 'Waypoint.h' header file:

class Waypoint
{
public:
int node_id;
float x,y,z;
float g,h,f;
int nConnections;
std::vector<int > connects;
Waypoint *parent;
bool onClosed;
bool onOpen;
};
//Comparison function used in the priority_queue
struct compare : binary_function <Waypoint *, Waypoint *, bool>
{
// Other stuff...
bool operator()(cons t Waypoint *x, const Waypoint *y) const {
return x->f > y->f;
}
};
My problem is as soon as I try to include 'Waypoint.h' in any .cpp
file, I have some errors:

error C2504: 'binary_functio n' : base class undefined
error C2143: syntax error : missing ',' before '<'

(I started to have this problem when I decided to split and reorganise
my files)

Anyone can help me please, I am just starting using stl priority
queues. I will be honest, I cut/paste this part from an example but I
really want to know how this comparison function exactly works.

Thanks a lot for your help

Eric

Jan 24 '06 #1
3 7037
er***********@g mail.com wrote:
Hello,

I managed to implement the AStar algorithm, however I have some trouble
using the priority queue, and the 'compare' function.
Here is my 'Waypoint.h' header file:

class Waypoint
{
public:
int node_id;
float x,y,z;
float g,h,f;
int nConnections;
std::vector<int > connects;
Waypoint *parent;
bool onClosed;
bool onOpen;
};
//Comparison function used in the priority_queue
struct compare : binary_function <Waypoint *, Waypoint *, bool>
{
// Other stuff...
bool operator()(cons t Waypoint *x, const Waypoint *y) const {
return x->f > y->f;
}
};
My problem is as soon as I try to include 'Waypoint.h' in any .cpp
file, I have some errors:

error C2504: 'binary_functio n' : base class undefined
error C2143: syntax error : missing ',' before '<'

(I started to have this problem when I decided to split and reorganise
my files)

Anyone can help me please, I am just starting using stl priority
queues. I will be honest, I cut/paste this part from an example but I
really want to know how this comparison function exactly works.


Perhaps you need to include the header that specifies binary_function
before using it?

#include <functional>

Perhaps you need to include the namespace std::?

struct compare : std::binary_fun ction<Waypoint *, Waypoint *, bool>

Both, perhaps?

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Jan 24 '06 #2
er***********@g mail.com wrote:
Hello,

I managed to implement the AStar algorithm, however I have some trouble
using the priority queue, and the 'compare' function.
Here is my 'Waypoint.h' header file:

class Waypoint
{
public:
int node_id;
float x,y,z;
float g,h,f;
int nConnections;
std::vector<int > connects;
Waypoint *parent;
bool onClosed;
bool onOpen;
};
//Comparison function used in the priority_queue
struct compare : binary_function <Waypoint *, Waypoint *, bool>
{
// Other stuff...
bool operator()(cons t Waypoint *x, const Waypoint *y) const {
return x->f > y->f;
}
};
My problem is as soon as I try to include 'Waypoint.h' in any .cpp
file, I have some errors:

error C2504: 'binary_functio n' : base class undefined
error C2143: syntax error : missing ',' before '<'

(I started to have this problem when I decided to split and reorganise
my files)

Anyone can help me please, I am just starting using stl priority
queues. I will be honest, I cut/paste this part from an example but I
really want to know how this comparison function exactly works.

Thanks a lot for your help

Eric


Looks like you just need to #include <functional> and/or qualify the
base class as std::binary_fun ction. (You shouldn't do "using namespace
std;" in a header.) See your STL book for more on binary_function , or
see this link:

http://www.sgi.com/tech/stl/binary_function.html

Did you want to know something else about the comparison function?

Cheers! --M

Jan 24 '06 #3
Thanks a lot for your help. In the code example I had 'using namespace
std', indeed I do not like using global declaration of namespaces so I
removed it...and I forgot to add the std:: prefix !!! I feel stupid ;)

Thanks for your link about binary_function , I really need to read a bit
more about that.

Thanks again for this quick answer ;)

Eric

Jan 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
5748
by: Aaron W. LaFramboise | last post by:
Hello, I understand that an easy way to make the standard std::priority_queue stable is by including an integer stamp with each node that is incremented each time a new node is pushed into the queue. However, no matter what reasonably-sized type I use for the stamp, eventually the stamp will 'wrap around' and possibly cause incorrect...
5
13221
by: Dan H. | last post by:
Hello, I have implemented a C# priority queue using an ArrayList. The objects being inserted into the priority queue are being sorted by 2 fields, Time (ulong) and Priority (0-100). When I enqueue, I do a binary search on where to put the object and then insert using that index and arraylist.insert(index, obj) The bottom of my...
3
1368
by: Erik | last post by:
Hi Everyone, I was thinking of how to do this for a while now and I cant get my head round it so I though I'd ask the experts! :-) What I am doing is reading in large amounts of data over TCP and saving it to disk. I receive alot of data from alot of clients so I do all this without processing the data. When a piece of data from a...
16
5383
by: Crirus | last post by:
hello I read somewhere about priority queue...what is that and Vb net have such class? -- Ceers, Crirus ------------------------------ If work were a good thing, the boss would take it all from you
4
10352
by: vfunc | last post by:
Is the STL priority queue a proper implementation of a heap with siftup algorithm etc ? How do you implement an STL priority queue (link to an example) ? Is there a resort method, why ? Thanks
3
4351
by: Chris Lasher | last post by:
Hello, I am working with large graphs (~150,000 to 500,000 nodes) which I need decompose node-by-node, in order of a node's value. A node's value is determined by the sum of its edge weights. When a node is removed from the graph, its neighbors' values must be updated to take into account the removed edges. I was told to look for a...
3
7402
by: PicO | last post by:
i need some explanation about the difference between priority queue & set & heap ... as they all sort the data in ( n log n ) ... but the only i see that priority queue only can pop the top ( maximum element ) while set and heap can erase any element ...
4
3412
by: jjh5030 | last post by:
This is a programming assignment. You are asked to work with pointers. Be aware that error messages are often not very helpful when your pointers point to bad locations. Therefore, reserve additional time for debugging. Implement a data structure Extended Queue using pointers. In addition to the usual queue operations Enqueue(x), Dequeue and...
14
16934
by: AlarV | last post by:
Hello everyone, here is my problem. I have to make a dynamic priority queue,which is a heap, and my book isn't helpful at all, so I have no clues on how to create it.. I read something like a static priority queue, which is an array heap, and for example i/2 is the father of i and so on.. the code of the static priority queue is this: int...
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
766
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.