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 -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -