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
Post a Comment