I'm trying to display some object information and it seems to work when I use a pointer to the object, but not when I pass the pointer to a different function. Hopefully, the code will better explain:
struct pcb {
int pid;
string name;
}
void showData(pcb* PCBobject) {
cout << "Number: " << PCBobject->pid << endl;
cout << "Name: " << PCBobject->name << endl;
}
void outputQueue(queue<pcb*> readyQueue) {
queue <pcb*> temp (readyQueue);
for (int i = 0; i < readyQueue.size(); i++) {
cout << "temp.front's number: " << temp.front()->pid << endl;
cout << "temp.front's name: " << temp.front()->name << endl;
showData(temp.front());
temp.pop();
}
}
The two cout statements in the outputQueue function display the correct information, but they're merely for testing purposes. I'd rather the information be displayed using a separate function: showData. However, showData throws a floating point exception and I can't figure out why. Am I passing the temp.front() pointer correctly?
Any help would be appreciated. Thanks.