C++98 specific:
The default constructor has been called once, the copy constructor has been called (trivially) twice, and destructor has been called 3 times.
Add a copy constructor which prints out something, and you would see what is going on.
Yes you are correct. I just verified and found copy constructor called twice after default constroctor. But didn't understand why copy constructor is getting called here?Can you please explain or redirect me to correct place on web ?
This constructor creates a vector of size 'count' by copying 'value' count 'times'.
Since you used a default value for the second argument:
a. Initialize 'value' using the default constructor.
b. Copy the value into the vector 'count' times using the copy constructor.
c. Destroy the default constructed object.
With C++11, the constructor is explicit vector( size_type count );. This constructor eliminates the gratituous default construct - copy - copy ... - destroy sequence; it directly default constructs the objects in situ.
If you have a choice, prefer C++11 over the obsoleted C++98.