Smart Pointers in C++ (Stop Using new?)

preview_player
Показать описание
Smart pointers can be a complicated subject, especially because there are multiple types! In this video we will talk about when you should use a smart pointer, and how each type works.

Timestamps:
00:00 - Intro
00:45 - Old School Pointers
02:00 - When do you Need Pointers
03:53 - use New
05:27 - Shared Pointers
07:30 - Other Smart Pointers
08:56 - Unique Pointer
09:39 - Smart Pointer Functions
11:45 - Weak Pointers
13:17 - Dereferencing a Weak Pointer
14:57 - Circular Reference
15:46 - Review

~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

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

let's go. This is what we need. Been using your lessons for learning anything. So far been great. thanks.

NathanatUuiu
Автор

As somebody who learned and uses mainly C++98, I'm glad to see videos about these newer C++ concepts I often forget about. 👍

andreasguettinger
Автор

I have never coded in C++ but lately I started learning Rust, while watching this video I can understand why the ownership/borrow model is powerful paradigm to enforce memory safety. It seems so easy to create bugs in C++

agailloty
Автор

Very well done. There were other videos on smart pointers that left me a bit confused. Yours is clear & understandable. Thank you

billbez
Автор

As great as always. Cannot wait to see the course.
Thanks!

aminramazanifar
Автор

Best video for smart pointers
Great bro🎉

suryadon
Автор

This video is very helpful, it's make me figured it out in one video huge thanks!

xbiohazardx
Автор

Thanks Caleb. Very clear examples and explanations.

MichaelCohen-sbtw
Автор

You’re a beast. Been watching for interview prep. You should start an udemy course!

sebastianroubert
Автор

As a user, you shouldn't be using new/delete anymore. As a library developer, you need it to implement RAII.

NoSpeechForTheDumb
Автор

but for a big game loop i would avoid smart pointers because there are slower?

Aragon
Автор

11:27 cracked up so hard. I do this all of the time when making videos.
Edit: wth? How did that even compile at 13:12. You have to declare the data type when making a shared pointer. Weird.

Sluggernaut
Автор

The level of abstraction is on a really akward level.
On one hand yeey nice, you don't have to delete pointers manually.
On the other hand, if you need to do anything more advanced like cloning, deep and or shallow copy and storing in containers, that requires even more work, knowledge and frustration than managing raw memory directly.
I find using smart pointers in very simple situations, where it's not necessary at all and in complicated situations I use raw pointers, just because I hate thinking about the obscure behavior of smart pointers.

panjak
Автор

hey bro. Please do a java springboot video or course?

fpldaily
Автор

This is one of the best coding tutorial videos I've watched. Clear, concise and complete. Thank you so much for your great work!

古川範和
Автор

I prefer new over make shared. If you need shared pointers, you most likely failed in your design. Unique pointers are the better option 99% of the time. Given you even need to put it on the heap.

nextlifeonearth
Автор

what I find weird about this code is that you are allowed to return a unique_ptr from a function without using the move function. Is seems that the compiler is smart enough to realize you are moving the unique_ptr from the function to the caller of the function.

Brad_Script
Автор

Why you using camel case btw and more can you make a video how to setup an editor for c++ development

midewestmond
Автор

Hi Caleb
i ran shared pointer example.its giving error .
error:smart_p3.cpp:6:34: error: conversion from ‘<unresolved overloaded function type>’ to non-scalar type ‘std::shared_ptr<int>’ requested
6 | std::shared_ptr<int> a= std::make_shared<int(5)>;
during compilation . which c++ compiler ur using..
I tried this on g++: gcc version 9.4.0
Please guide
Thanks
Abhishek

abhishekkhanchi
Автор

Ownership, lifetime, ... After learning some basic Rust, all of these make sense. 😀🦀

hiankun
visit shbcf.ru