As a C programmer doing C++ stuff a few things are still confusing to me. One is scope. Consider the following code
What happens to c and what happens to the vector when foo exits? std::vector<T>.push_back takes as an argument a T&, so my understanding is that the vector contains a reference to c, which is located on foo's stack. When foo returns, c should get nuked, which should screw up the vector. Is that right?Code:#include <vector> using std::vector; class A_Class{ public: A_Class(int x); // some stuff }; void foo(vector<A_Class> *v){ Class c(42); v->push_back(c); } int main(){ vector<A_Class> *v = new vector<A_Class>(); foo(v); return 0; }