Solved

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

Posted on 2004-10-01
1
170 Views
Last Modified: 2013-11-20
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
Comment
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
  • Learn & ask questions
1 Comment
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 20 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 117
Separate into files by filename 12 92
NotAlone Challenge 20 93
Authenticate using sesu from script 7 159
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question