Solved

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

Posted on 2004-10-01
1
166 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
1 Comment
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 20 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now