std::move and the Move Assignment Operator in C++

preview_player
Показать описание


This video is sponsored by Skillshare.
Рекомендации по теме
Комментарии
Автор

I really wish I had've just watched your entire C++ series instead of listening in any of my lectures. This has been miles more helpful and easy to understand than any programming class I've had.

MrSuperdude
Автор

I've just aced a C++ technical interview thanks to this video. Your ability to explain is unparalleled. Keep doing the good work!

lucascoef
Автор

A good ways to understand std::move() is that you are basically saying "I don't need the object that I am passing anymore. I am allowing someone to steal from it."

Dante
Автор

This is something I did so many times in C, but my teachers never told me it was a concept (move). It's much clearer when to do what now and the class abstraction we can do in C++ helps the code to be cleaner.

Drastonar
Автор

14:05 distinction between constructor and assignement operator, that's why I rather prefer to use {} brackets with new object creation and use the = only for assignement operator :)
(For instance : String name{"Cherno"};)
By the way, huge and awesome work, thanks !

fabricedelannay
Автор

Not a clue what most of what you said means on a technical level. But still couldn't stop watching. Great video.

C++ gods help me 😭

brandoncfrey
Автор

I like the sentence "steal everything from Apple" 🤣

RogerTannous
Автор

I did not understand std::move() until I watched this. To give some background, I was first exposed to C++ in 1994 but moved away from it before r-value references were a thing.

I like the examples he provides. The problem I have with most explanations is that they use words like "tells the compiler it can cannibalize the object" or some such nonsense. That leaves the impression that the compiler is doing some type of cannibalizing or other magic behind the scenes.

Saying it just turns the object to an r-value reference and as a side effect can cause the move constructor or move assignment operator to be called. The person cannibalizing is not the compiler, it is the implementor of those operations.

After seeing this I wrote a simple class like he had and played around with it. It is not nearly as complicated as I thought.

justinjames
Автор

1. Instead of casting using
(T &&)var you can use std::move(var)
2. A good ways to understand std::move() is that you are basically saying "I don't need the object that I am passing anymore. I am allowing someone to steal from it."
3. We need to always delete the current data before shallow copying the other data. Also we need to point other data to nullptr.

ameynaik
Автор

after he said "implicit conversion and call into this specific string constructor" my furnature started floating, help

unmeinks
Автор

Daym, my man just explained everything very clearly. Thank you, it's usually explained very complicated

AurelianoShowsTheWorld
Автор

Great video! This is my favorite C++ series. I hope you make one on perfect fowarding soon.

mikeweathers
Автор

I now realize I still dont know the basics of c++

boondocksripoff
Автор

you definitely made a cool explanation of the std::move functionality - thanks, this is going to help many developers I think

johnnyserup
Автор

Move semantics is a topic difficult to comprehend. Your in depth explanation made it very clear.

deepikagoyal
Автор

Thank you for the video. I think what "clicked" hardest for me was when I learned that the assignment operator, by default, only moves the values inside an object to a different object, if the object that it is being moved into pre-existed - which is why we overload the assignment operator, so that we can do this, even when the object that the data is being moved into is being initialized. Or at least, this is how I think it works. If I'm misunderstanding, I would love some clarification.

jonathanp
Автор

Your examples make move semantics really easy to understand. Please explain copy and swap idiom too.

Rohith_E
Автор

Dude, you're amazing. Your videos are helping me a lot!

MarcosVinicius-bdbi
Автор

That's amazing, thank you so much Mr Cherno!
By the way, a lot of what I know of C++ I've learned from you, so a huge thanks, this has been very helpful!
(Shoutout to Corey Schafer too for teaching me Python!)

davidm.johnston
Автор

I never realized the difference between a constructor being called with '=' vs an assignment operator being called with '=', nice bonus information!

Mystixor