|
-
Mar 7th, 2003, 12:23 AM
#1
Thread Starter
Addicted Member
Need to get around some pointers
I have a template class that implements a PriorityQueue, the important thing about the PQ is that it requires the < operator and the == operator of the typename that I give it.
So it works great with ints, PriorityQueue<int> is great. But if I use PriorityQueue<int*> i have a problem because it doesn't deference the pointer when doing the comparisons on it. I'm guessing it just compares the pointer address or something.
How can I get it to derefence if the typename if its a pointer and not if its not a pointer. I need this for passing a class as the typename that overloads the < and == ops.
NOMAD
-
Mar 7th, 2003, 08:09 AM
#2
Fanatic Member
use a try...catch? or make a bool var that you set true if it is a pointer and false if its not? or would it be possible to make new operators? <*, ==*? (I forget if its possible to define your own operators)
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Mar 7th, 2003, 10:06 AM
#3
Frenzied Member
Originally posted by DNA7433
use a try...catch? or make a bool var that you set true if it is a pointer and false if its not? or would it be possible to make new operators? <*, ==*? (I forget if its possible to define your own operators)
Its not.
The easy way is to write a container struct:
Code:
struct _that_holds_int_pointers
{
public:
bool operator ==(_that_holds_int_pointers& rhs);
bool operator <...;
int* member;
};
Override those operators, and compare the *member value.
The STL priority_queue takes as one of its template parameters the typename of a comparison object which does the comparisons between members. Using this method, one could simply write a new comparison object to use.
Z.
-
Mar 7th, 2003, 06:59 PM
#4
Thread Starter
Addicted Member
Thanks guys I'll try that
NOMAD
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|