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()(const 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_function' : 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 3 7028 er***********@gmail.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()(const 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_function' : 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_function<Waypoint *, Waypoint *, bool>
Both, perhaps?
Ben Pope
--
I'm not just a number. To many, I'm known as a string... er***********@gmail.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()(const 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_function' : 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_function. (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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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
|
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....
|
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 (...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
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...
| |