I am trying to override the operator << for my stack class to make it print all items, plates in this case, but I am getting a segmentation error. I don't know what this means or how to fix it.
ostream& operator << (ostream &out, Stack &stack){
int a = stack.getStackCount();
string outString = "";
PlateNode temp = PlateNode(stack.getTop().getPlate());
for(int i =0;i<a;i++){
outString = outString + ", " + temp.getPlate().getName();
temp = temp.getNextNode();
}
out << outString;
return out;
}
That is where I tried to override the operator, and my main is:
int main()
{
Stack nullStack = Stack();
nullStack.push(pNode);
nullStack.push("me");
cout <<"Reached c"<<endl;
cout<<nullStack;
}
The error was not there before the final line in main was entered. Please Help!
Edit:This is my entire code if that helps, sorry it is not commented fully:
https://docs.google.com/document/d/16pg01muz0S5IMlXBahdL-JyVE5y7buzOVHYEOn_jyvE/edit?usp=sharing