c++ std::stack content will not be free when leaving function -


i think in function err_fun, stack em free when leave err_fun(), content of em free in same time, , why can still right answer in main function stack st?

thanks.

#include <stack>  stack<int> st;  void err_fun() {     stack<int> em;     st.swap( em ); }  int main() {     err_fun();      //... operation stack st.     return 0; } 

the content of em copied on that's asked when did swap. since st global in scope it's not destroyed.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -