#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 vec; int i1; //student studentObj( 1 ) ; student* ptr ; ptr = new student( 1 ) ; // display the original size of vec cout << "vector size = " << vec.size() << endl; // push 5 values into the vector vec.push_back( ptr ); // display extended size of vec cout << "extended vector size = " << vec.size() << endl; // access 5 values from the vector cout << "value of vec [" << 0 << "] = " << vec[0]->id << endl; // use iterator to access the values delete ptr ; //Using the vector after the object has been deleted. cout << "value of vec [" << 0 << "] = " << vec[0]->id << endl; return 0; }