Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Why does't this work. faint.........about priority_queue

Posted on 2004-10-01
Medium Priority
172 Views
I save a sample Struct

struct Packet
{
unsigned int      l_Priority  : 5;
unsigned int      CRC        : 8;

bool operator < (Packet* msg) const
{
return l_Priority < msg->l_Priority ;
}
bool operator > (Packet* msg) const
{
return l_Priority > msg->l_Priority ;
}
};
in a priority_queue
typedef std::priority_queue <const Packet*> Msg_Queue;
but it not works!!
I try to excute following test code
Packet* p1;
Packet* p2;

p1 = new Packet();
p2 = new Packet();

p1->l_Priority = 1;
p2->l_Priority = 3;

if (p1 > p2)
printf("p1 > p2\n");
else
printf("p1 < p2\n");
the result seems always p1 > p2, even though p1->l_Priority < p1->l_Priority
0
Question by:reneschy
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
1 Comment

LVL 55

Accepted Solution

Jaime Olivares earned 40 total points
ID: 12205442
Try with this:

struct Packet
{
unsigned int     l_Priority  : 5;
unsigned int     CRC      : 8;

bool operator < (Packet& msg) const
{
return l_Priority < msg.l_Priority ;
}
bool operator > (Packet& msg) const
{
return l_Priority > msg.l_Priority ;
}
};

int main()
{
Packet* p1;
Packet* p2;

p1 = new Packet();
p2 = new Packet();

p1->l_Priority = 1;
p2->l_Priority = 3;

if (*p1 > *p2)
printf("p1 > p2\n");
else
printf("p1 < p2\n");
system ("Pause");
return 0;
}
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
###### Suggested Courses
Course of the Month7 days, 17 hours left to enroll