C++ From Scratch: Move Constructors
Вставка
- Опубліковано 18 жов 2024
- In this video we learn about the basics of move constructors in C++!
C++ Reference move constructors: en.cppreferenc...
C++ Reference vector push_back: en.cppreferenc...
For code samples: github.com/coff...
For live content: / coffeebeforearch
It would be nice to see print out of destructors too with this prints
This would be another example of the adage that for C when they saw a gap they just wrote more code, for {insert other languaage, C++ generally but these days you see it a lot} when they saw a gap they added syntax. While I do think it could've been designed in a better way, it at least made some kind of sense given that it's just doubling the symbol used for references. But I still wish they had gone with the @ symbol.
If I do a second push, e.g, like the following,
my_vector.push_back(std::move(p1));
my_vector.push_back(std::move(p2));
why do I see a copy constructor running in the end?
The vector probably needed to allocate space to hold more than one element, and had to copy the first element to the newly allocated space
@@CoffeeBeforeArch I see. Thank you for the response! Your videos are amazing btw! Thanks for making them.