Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-01
1
Medium Priority
?
174 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

972 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