I have two structs (part of the assignment). A list of one — Activity, contained in the other — Process. Then, several of the parent Process struct are contained in a priority queue.
struct Activity {
public:
int time;
string type;
Activity(int newTime, string newType):
time(newTime),type(newType){}
};
struct Process {
public:
string PID;
int arrivalTime;
int priority;
list<Activity> activityQueue;
Process( string newPID, int newTime, int newPriority, list<Activity>
newActivityQueue):
PID(newPID),arrivalTime(newTime), priority(newPriority),
activityQueue(newActivityQueue){}
};
I get the following error…
main.cpp:206:61: error: passing ‘const std::list<Activity>’ as ‘this’ argument of
‘void std::list<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Activity,
_Alloc = std::allocator<Activity>, std::list<_Tp, _Alloc>::value_type =
Activity]’ discards qualifiers [-fpermissive]
…when I attempt to push_back an Activity to a Process’s activityQueue.
Activity currentActivity = cpuQueue.top().activityQueue.back();
currentActivity.time--
cpuQueue.top().activityQueue.push_back(currentActivity);
std::priority_queue<T>::top()returns a const reference to the top item: this is so you can’t mutate it in-place and break the ordering constraints.If you’re happy that the activity list is an implementation detail that won’t affect the position of a process in the cpu queue, you could just make
Process::activityQueuemutable.Otherwise, you should pull the process out of the queue, modify it, and re-add.