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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -