I'm trying to make a program that plays a card game. I currently have a function that returns a card object pointer. This works perfectly. I am able to use that card pointer fine. The problem is that when I put that card pointer into a vector or list, and try to access the pointer subsequently, I get back gibberish.
I assume that I'm not assigning the pointer correctly in the list or I'm not accessing it correctly, but I don't know how the fix either. Please help:
I suspect the problem is that you do not have valid memory for this card. Does taking_turns returned a new'd card? Can you post taking_turns?
EDIT:
in fact I'm sure that's the problem. You must be returning a pointer to a local object. push_front is modifying the stack, thereby corrupting your 'card'
The easy solution here is to just not use pointers. Just return a full card object, put a full card in the list, etc, etc. No need for pointers here.