Modern C++: Upgrade Your Skills with Shared Pointers!

preview_player
Показать описание
Dave take you a tour of some core advanced C++ features including smart pointers, weak pointers, constructor aliasing, custom deleters, and atomic operations. All examples are presented in compilable code that can be downloaded below.

Рекомендации по теме
Комментарии
Автор

As someone who writes a lot of ANSI C for tiny microcontrollers, seeing these great features of C++ is giving me courage to write for much larger microcontrollers (STM32, esp32, etc.) Keep the information coming!

babyeatingpsychopath
Автор

Note that std::atomic_load and std::atomic_store on std::shared_ptr arguments are deprecated as of C++20. If you need to atomically change a std::shared_ptr, you should be using a nowadays.

billyofthefuture
Автор

I used to code in C/C++ when I was working - but after I retired, I guess I looked for something different... I started with a MITS computer and the Extended Basic on cassette tape. So I went looking for a good modern Basic.... and I found Visual Basic 2008 and nowadays 2017.... it is at once Basic, but with a heavy dash of Class structure and a vastly improved function library. In my retirement (some 20 years now) I have completed several major projects (largely for myself) with Visual Basic, and I love it!!! I even did a minor project to create a clock with multiple threads using the Basic interrupt routine. Very neat.... I wanted a digital clock with giant numbers so I could see them (I am sight challenged due to diabetes)... and after awhile, I hung several things off that program, like some code to play mp3s in the background while I coded. But I guess there's no chance of you covering VB, and most of the sample code I find online to help VB users is in C#, so I am having to learn that in self-defense. So C# coverage would be a great help for us VB users.

pawnslinger
Автор

Very cool video. I hope you keep doing these. Last time I used C++ was back in college before all these were added to the language, so it's nice seeing how things have changed.

Inuyasha
Автор

Thank you ! I have very little experience in C++, but I am learning Rust currently, after many years of Java, just out of curiosity, and to satisfy a desire to get closer to the hardware. This video helps me to understand many of the reasons behind Rust's choices. Rust looks like C++ with guard-rails, but the guard-rails are here if you know them, and use them correctly, which makes it look less "scary" than it really is. Makes me want to study C++ again :)

Yakeru
Автор

Thanks for the super explanation. I hope this playlist gets more videos. It is very exciting to learn from someone who has been involved with the technology for so many years.

SwapChain
Автор

Excellent. I haven't looked at C/C++ for a lot of years. The new "smart" functions are brilliant.

johnmckown
Автор

Nice introduction to this topic. One suggestion: simple but realistic/practical examples are most helpful to newcomers. The fclose() custom deleter was a good one. With weak_ptr I would recommend showing something like a Document containing a Page containing a Paragraph. Start with parents owning their children as a shared_ptr. Then add back-pointers. Initially used shared_ptr for these too, but then demonstrate how cutting a Page from one Document and pasting it to another would create a memory leak. Then show how weak_ptr would fix this.

markmuir
Автор

Thank you so much for making these. I was stuck with C++ 98.

jackpisso
Автор

Gotta say this single video used more shared_ptrs than in all my codebases combined. I generally prefer a unique_ptr at all times and tend to redesign before I use a shared_ptr.

nextlifeonearth
Автор

Learning to program videos are truly the best. I love watching the Cherno's channel and if you started doing these I would love to watch yours too.

scriptles
Автор

Thank you so much for the effort, I've learned something today. These in-depth tech themes are very vital and crucial to future programmers and I'm waiting for more and more to come .Thank you again, always looking forward !

The_Gray_Zone_Man
Автор

Incidentally I was just in the middle of rewriting one of my old programs to use these instead of raw pointers. The unfortunate thing is that I knew the name unique_ptr when I was originally creating it but never looked into what it did because I assumed it was overcomplicated for what I needed to do. In reality, using it would've been simpler and saved me time...

tomysshadow
Автор

Another great instructional video! I look forward to you making more of these C++ videos. One on proper techniques for handling multi-threaded programming would be great.

rickpoeling
Автор

I've not used C++ seriously in absolute ages. I never knew they've added so many cool stuff in that language. I rarely write code nowadays, but when I do its usually C or C#. I've been on the receiving end of pointe problems for a long time, so seeing them being mitigated somewhat in an old language looks great.
Still new code in the company I work for that used to require C will probably be done in Rust or Zig. We are still evaluating them for embedded applications.

Nik
Автор

Pretty sure it would go:
I am a Base.
I am a Derived.
I am a Derived.

Great stuff, like the more advanced topics. And I don't even do C++ :)

MitjaSkuver
Автор

Dave I would love it if you did a video on lambdas and the std::algorithm library! Thanks for the videos, these are great, I am sending these to tons of people.

scienceandmathHandle
Автор

Your channel is truly a goldmine of knowledge. Thank you for the time and effort you put into these videos.

VultureGamerPL
Автор

Thank you for an excellent description. I am less confused now about the copying of shared pointers.

keithlambell
Автор

I was having problems with dangling pointers a long time ago. I switched to shared/weak pointers and it saved my life.

poopingnuts