I think I see your problem. It has to do with your methods :
int top()
{
stack<int> cn ; cn = transactions.top()->content;
return cn.empty() ? 0 : cn.top();
}
int pop()
{
stack<int> cn; cn = transactions.top()->content;
if(cn.empty())
return 0;
int t = cn.top();
cn.pop();
return t;
}
The problem has to do with what the comments point at. You are creating a copy of the content stack in both of those. That is not a good idea at all. Plus, in the case of
pop
, you are popping from the copy, not your actual stack. It would be better to make that a reference so the operations are performed on the actual members of the object and not copies. Here is how that could look using references.
using stackint = std::stack< int >;
int top()
{
stackint & cn = transactions.top()->content;
return cn.empty() ? 0 : cn.top();
}
int pop()
{
stackint & cn = transactions.top()->content;
if(cn.empty())
return 0;
int t = cn.top();
cn.pop();
return t;
}