来自main.cpp 断言错误在这里
if(!((CPU1.peek()).isExecuting())) {
cout << "Running: " << CPU1.peek().running << endl;
(CPU1.peek()).execute();
cout << "Running: " << CPU1.peek().running << endl;
assert((CPU1.peek()).isExecuting());
((PCB)CPU1.peek()).setStart(slice);
((PCB)CPU1.peek()).setWait(slice-((PCB)CPU1.peek()).getArrival());
averageWait1 += ((PCB)CPU1.peek()).getWait();
cpu1PCBTotal++;
length1 = ((PCB)CPU1.peek()).getLength();
}
PCB.h
class PCB
{
private:
/**
* this process ID
*/
int pid;
/**
* the nice (priority) value of this process
*/
int priority;
/**
* running status 0=idle 1=running
*/
int running;
public:
/**
* Creates a simulated job with default values for its parameters.
*/
PCB()
{
priority = 19;
running = 0;
arrived = 0;
length = 0;
}
PCB(int id, int pval, int run, int arr, int len)
{
pid = id;
priority = pval;
running = run;
arrived = arr;
length = len;
}
bool isExecuting() const
{
return (running == 1);
}
void execute()
{
running = 1;
}
heap.cpp
template <typename E>
Heap<E>::Heap()
{
// compiler-generated code .. no need to implement this
}
template <typename E>
Heap<E>::~Heap()
{
while(tree.size() > 0)
tree.pop_back();
}
template <typename E>
bool Heap<E>::isEmpty() const
{
return tree.size() == 0;
}
template<typename E>
void Heap<E>::insert(E item)
{
tree.push_back(item);
int place = size()-1;
int parent = (place-1)/2;
while(parent >= 0 && tree[place] > tree[parent]) {
swap(place, parent);
place = parent;
parent = (place-1)/2;
}
}
template<typename E>
E Heap<E>::remove() throw (HeapException)
{
E root = tree[0];
tree[0] = tree[size()-1];
tree.pop_back();
reheapify(0);
return root;
}
template<typename E>
const E& Heap<E>::peek() const throw (HeapException)
{
return tree[0];
}
template<typename E>
int Heap<E>::size()const
{
return tree.size();
}
template<typename E>
void Heap<E>::swap(int place, int parent)
{
E temp = tree[place];
tree[place] = tree[parent];
tree[parent] = temp;
}
template<typename E>
void Heap<E>::reheapify(int root)
{
int l = root*2+1;
int r = root*2+2;
if(l < size()-1) {
if(r < size()-1)
if(tree[root] < tree[r]) {
swap(root, r);
reheapify(r);
}
if(tree[root] < tree[l]) {
swap(root, l);
reheapify(l);
}
}
}
断言失败了,我不明白为什么......请帮助,谢谢
顶部是主要功能,底部是PCB.h; CPU
类是一个堆
最初是强制性的CPU1.peek(),因为它给了我错误&#34;传递&#39; const PCB&#39;作为&#39;这个&#39;论证抛弃了限定符&#34;所以我想我需要帮助调用CPU1.peek()。execute()