0

I'm pretty new to STL and am trying to fill in for some code that creates a priority queue with the top of the queue always being the largest value of the queue. The question specifies not to include the functional header (i.e. no greater<>). So here's what I go for:

int main()
{
    struct hi
    {
        bool operator () (double & a, double & b) const
        {
          return a > b;
        }
    };
      priority_queue < double, vector<double>, hi > q;
    //... other operations.

When I compile this is MSVC, everything goes well and I get the desire result when I call q.top() and print the top value. But when compiling this is ideOne or Eclipse with GCC, I get a compilation error about "invalid type declaration before ;". What am I doing wrong here?

Note: I was supposed to fill in a black inside the main function.

kevw22
  • 163
  • 1
  • 2
  • 8
  • In which line of the code do you receive the "invalid type declaration before ;" error message? – Roberto May 03 '15 at 22:56
  • 1
    You are not explicitly qualifying `std::priority_queue`, so do you have `using std::priority_queue` somewhere above? – Vaughn Cato May 03 '15 at 22:59
  • Welcome to Stackoverflow. Please read about [SSCCE](http://sscce.org) and fix your question accordingly :-) – Arne Mertz May 03 '15 at 23:01
  • @VaughnCato adding `std::vector` to that. – WhozCraig May 03 '15 at 23:05
  • 2
    [You can't use local classes as template arguments before C++11](http://stackoverflow.com/questions/8203750/local-classes-c03-vs-c11). Have you enabled C++11 or later? MSVC enables the latest standard (as far as it has been implemented) by default, GCC requires a flag `-std=c++11` (or 0x, or 1y or 14) – Benjamin Lindley May 03 '15 at 23:06
  • Besides the local class issue, it is advisable for the comparison's parameters to be `const` references, e.g. `bool operator () (const double & a, const double & b) const` or values, e,g, `bool operator () (double a, double b) const`. A comparison should not modify the objects passed to it. – juanchopanza May 04 '15 at 05:38

0 Answers0