Thread: Priority Queue :: C++

  1. #1

    Priority Queue :: C++


    Visual C++ .NET outputs this error when I try to declare a priority queue with reverse sorting.

    // Assuming program runs and before I added the following.
    #include <queue>
    #include <functional>

    std:riority_queue<int, std::greater<int>> m_nQueueList;

    // I try this declaration, but receive the exact same
    // error everytime.

    std:riority_queue<int, std::vector<int>, std::greater<int>> m_nQueueList;

    Here is the error from Visual C++ .NET

    C2065: 'm_nQueueList' : undeclared identifier
    error C2143: syntax error : missing '>' before ';'
    error C2146: syntax error : missing ',' before identifier 'm_nQueueList'
    error C2208: '<Unknown>' : no members defined using this type
    error C2947: expecting '>' to terminate template-argument-list, found '>>'
    error C2976: 'std:riority_queue' : too few template arguments

    Does anyone know what the problem is?


  2. #2
    std::priority_queue<int, std::vector<int>, std::greater<int>> m_nQueueList;
    does this '>>' look familair? It is being parsed as the left shift operator. You need a space between the two brackets.

    std::priority_queue<int, std::vector<int>, std::greater<int> > m_nQueueList;

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    when u post code use the code tags like
    your code here

    but instead of ( and ) put [ and ]
    Email: || AIM: MisterSako || MSN:

    -the shroom has spoken

  4. #4
    Okay. Thanks.

    Added a space in between ">>" fixed it.

    Here is the working solution.

    std:riority_queue<int, std::vector<int>, std::greater<int> > m_nQueueList;
    I would have never guessed the problem had to do with a missing space. That space operator is tricky.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. Priority Queue Help
    By cjwenigma in forum C++ Programming
    Replies: 6
    Last Post: 11-15-2007, 12:48 AM
  4. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 09:09 PM
  5. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 11:39 AM