From the cpp documentation for std::vector, I see this:
void push_back ( const T& x );
I understand that push_back makes a copy of the object that I pass. But, why is the signature const T& ? By looking at this, I initially thought it takes a const reference of whatever object that I push to the vector.
The object you push is passed by reference to avoid extra copy. Than a copy is placed in the vector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With