Mega Code Archive

 
Categories / C++ Tutorial / Vector
 

Elements Being Created, Assigned, and Destroyed

#include <iostream> #include <vector> using namespace std; class Element {    public:    Element();    Element( const Element& );    ~Element();    Element& operator=( const Element& ); }; inline Element::Element() { cout << "\nIn default constructor"; } inline Element::Element( const Element& ) { cout << "\nIn copy constructor"; } inline Element::~Element() { cout << "\nIn destructor"; } inline Element& Element::operator=( const Element& ) {    cout << "\nIn assignment operator";    return *this; } int main( ) {    cout << "Constructing Vector With Three Elements";    vector<Element> d( 3 );    cout << "\n\nDeleting First Element";    d.erase( d.begin() );    cout << "\n\nDeleting All Elements";    d.clear(); }