I have a struct call 'A', which has an attribute 'i', like this:
typedef struct a {
a() { i = 0;}
int i;
} A;
And I would like to maintain a stack of A in my Main class:
class Main {
public:
void save();
void doSomethingToModifyCurrentA();
void restore();
private:
A currentA;
stack<A> aStack;
}
I would like to write the function save() which save the current values of A (e.g. i) to the stack and I can go on doSomethingToModifyCurrentA() to change currentA. And then later on, I can restort A by calling restore().
My question are
- How can I allocate memory for a copy of A to the 'stack'?
- How can I pop out the copy of A and free the memory and restore the value of 'currentA'?