I'm getting malloc: pointer being freed was not allocated error.
I suspect that it's one of my function that uses pop_front().
This is the basic run down of what I was planning to do with my code. I have a list that acts as a Queue, that holds pointers. I dequeue from my list into a vector, so I place the list's pointer at the front and push_back into the vector. I dequeue from the list since it's suppose to be in the vector.
This is the mock code that I have with the functions:
struct A{
int x;
};
class myListClass{
public:
shared_ptr<A> getFront(){
return myQueue.front();
}
// I think this is giving the malloc error.
void deleteFront(){
myQueue.pop_front();
}
void addIntoQueue(shared_ptr<A> item){
myQueue.push_back(item);
}
private:
list < shared_ptr<A> > myQueue;
};
class myVectorClass{
public:
void addIntoVector(shared_ptr<A> item){
myVector.push_back(item);
object.deleteFront();
}
private:
vector < shared_ptr<A> myVector;
myListClass object;
};
int main(){
shared_ptr<A> obj (new A);
myListClass list;
myVectorClass v;
// Adds object pointer to my list
list.addIntoQueue(obj);
// Adds object pointer into my vector and removes from list
v.addToVector(list.getFront());
}
Why does the myVectorClass have a myListClass object? (And why does myVectorClass::addIntoVector attempt to remove an element from an empty list?)
While I'm asking silly questions: Why didn't you supply a compilable code snippet that illustrates the problem rather than a piece of code that cannot be compiled? (The method on line 45 does not exist in myVectorClass and you're missing a > on line 33.)
#ifndef PCB_H
#define PCB_H
#include <memory>
#include <list>
staticint totalPID = 0;
class PCB{
public:
// When a PCB object is created, the PID is increased by 1
// Input 'A' should create a PCB object
PCB()
{
totalPID++;
}
void createNewPID(){
pid = ++totalPID;
}
void setPID(){
pid = totalPID;
}
// Returns the PID of the PCB
int getPID(){
return pid;
}
private:
int pid;
};
#endif