#include #include #include using namespace std; //Use pointers to avoid a copy class student { public: int id ; student( int idP ) { id = idP ; cout << "Constructor called for ;" << id << endl ; } student( const student& obj1 ) { id = obj1.id ; cout << "Copy Constructor called for ;" << id << endl ; } ~student( ) { cout << "Destructor called for ;" << id << endl ; } }; int main() { // create a vector to store int vector< shared_ptr > vec; { shared_ptr valuePtr( new student(1) ) ; // display the original size of vec cout << "vector size = " << vec.size() << endl; // push 5 values into the vector vec.push_back( valuePtr ); //valuePtr gets destroyed here but //delete is not called for valuePtr } cout << "value of vec [" << 0 << "] = " << vec[0]->id << endl; return 0; }