I’ve looked at the C++ FAQ and other places, such as this answer and the surrounding answers in that section, and I can’t seem to figure out how to do what I want. I’m using gnu C++ on a Linux box.
I’m trying to create an simple simulation of a Linux scheduler – it was a homework lesson last semester that I couldn’t do at all, and got a 0 on, but it’s irritating me no end and I’ve been working on and off on it for months. I’ve created a couple classes: proc, which includes a bunch of data objects that are information about a process, including its priority, and another class called priority_array that includes 13 queues – these are just standard C++ queues using the
#include <queue>
header, and to define them I’ve done
queue<proc> queue0;
queue<proc> queue1;
queue<proc> queue2;
queue<proc> queue3;
queue<proc> queue4;
…
queue<proc> queue13;
Now, each process can have a priority level from 0 to 139. Processes with priority 0-9 will go into queue0, 10-19 will go into queue1, and so forth, up to .
So I was working on an add() function, to add each process to the priority array, and obviously if I had an array of pointers to the above queues, I could just apply a simple “Put it in queue int(priority/10)” rule. Say the array was called which_queue, and a pointer to queue0 was in which_queue[0], pointer to queue1 in which_queue[1], etc., then I could just do:
which_queue[(int)priority/10].push(whatever_process);
(or which_queue[(int)priority/10]->push(whatever_process), depending on whether I need the . or -> operator in this case)
to add the current process to its queue. But since queues themselves are a class … and I’ve created queue objects in my priority_array class … and I’m trying to access those objects from a member function of the priority_array class … I don’t know how to do it. This many levels of classes is just confusing the hell out of me.
Can anybody tell me what I need to do to make this kind of thing work? It would be handy in a lot of other situations too.