Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:25:03+00:00 2026-06-10T02:25:03+00:00

I am working with std::priority_queue for the first time for a University assignment. The

  • 0

I am working with std::priority_queue for the first time for a University assignment. The assignment is a simulation of process scheduling. I would like to pass a parameter to my Comparison struct constructor to initialise and I thought I saw it on another forum, but I’m unable to find the source again. I looked on SO before posting but I didn’t see anything similar.

Here is my priority_queue:

/* schedules.hpp / .cpp */
#include "process.hpp"

namespace my = procschedassignment;

int tick = 0;
std::priority_queue<my::Process, _
        std::vector<my::Process>,
        PrioritiseHighestResponseRatioNext(tick) > rq;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
line 100 - compiler errors are here
// ...

Here is my Comparison struct:

/* prioritise_process.hpp / .cpp */
#include "process.hpp"

namespace my = procschedassignment;

struct PrioritiseHighestResponseRatioNext {
    public:
        explicit PrioritiseHighestResponseRatioNext(int const& cpu_time)
                : cpu_time_(cpu_time) {};
        bool PrioritiseHighestResponseRatioNext::operator()(my::Process const& lhs,
                my::Process const& rhs) {
            bool ret;

            if (lhs.wait_time() > cpu_time_) {
                ret = (lhs.ResponseRatio() > rhs.ResponseRatio());
            } else if (rhs.wait_time() > cpu_time_) {
                ret = (lhs.ResponseRatio() < rhs.ResponseRatio());
            }

            return ret;
        };

    private:
        const int cpu_time_;
};

The compiler errors I get with this code are:

../src/schedules.cpp:100: error: ‘time’ cannot appear in a constant-expression
../src/schedules.cpp:100: error: template argument 3 is invalid
../src/schedules.cpp:100: error: invalid type in declaration before ‘;’ token

Is it possible to have a parameterised Comparison struct with std::priority_queue?
I am new to STL so I apologise that I don’t have a better understanding of what’s happening here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:25:04+00:00Added an answer on June 10, 2026 at 2:25 am

    You are trying to pass an object as template-parameter. This will not work. You should provide your comparator as argument to the constructor, and the type of the comparator as template-argument.

    // declare type
    typedef std::priority_queue<my::Process,
                                std::vector<my::Process>,
                                PrioritiseHighestResponseRatioNext > process_queue;
                                // ^^^ just a type, no object ^^^
    // create object
    process_queue rq(PrioritiseHighestResponseRatioNext(tick));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently been working with code that looks like this: using namespace std; class
Working with MS Access for the first time and coming across a few problems
Alright, so we know functions in the STL like std::fill(boolContainer.begin(), boolContainer.end(), false); I'm working
For some reason this sort code is not working as I would expect: std::fstream
While working on this question , I noticed that GCC (v4.7)'s implementation of std::function
I'm working with std::list<std::string> in my current project. But there is a memory leak
I have a flyweight pattern working in serial where the factory uses std::map to
I'm working on a very basic game and I have a std::list collection of
I am working with a std::vector to hold some objects that have dynamically allocated
I am working with 2 libraries. One takes in and returns std::string s while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.