I came across this code recently but don't quite understand what's going on.
auto c = vector<int> {};
What is the vector constructor returning?
Then this code:
c = vector<int> {1,2,3,4,5 };
Is the second c
at a different memory location to the initial c
?
Is the destructor called when c
is reinitialised?
I searched the internet but could not find any examples of the above code.
How is the above different to
vector<int> c {};
Thanks in advance for any help.
"As jrd1 says, it's a C++11 feature.
The keyword auto
basically means that you let the compiler "guess" the type of the variable.
So c
is a regular vector<int>
.
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