Smart Pointer In C++

Sdílet
Vložit
  • čas přidán 13. 09. 2024
  • JOIN ME
    -----
    CZcams 🎬 / @cppnuts
    Patreon 🚀 / cppnuts
    COMPLETE PLAYLIST
    ------------
    C++ Tutorial For Beginners :
    • Introduction To C++
    STL (Standard Template Library) :
    • STL In C++
    ThreadIng In C++ : • Multithreading In C++
    Data Structures: • Data Structure
    Algorithms: • Binary Search
    Design Patterns: • Factory Design Pattern...
    Smart Pointers: • Smart Pointer In C++
    C++14: • Digit Separator In C++
    C++17: • std string_view in C++...
    C++ All Type Casts: • static_cast In C++
    INTERVIEW PLAYLIST
    ------------
    C++ Interview Q&A: • Structural Padding & P...
    C++ Interview Q&A For Experienced: • How delete[] Knows How...
    Linked List Interview Questions: • Find Kth Node From Bac...
    BST Interview Questions: • Search Element In Bina...
    Array Interview Questions: • Reverse An Array
    String Interview Questions: • Check String Is Palind...
    Bit Manipulation Questions: • Find Set Bit In Intege...
    Binary Tree Interview Question: • Invert Binary Tree
    Sorting Algorithms: • Bubble Sort
    C++ MCQ: • Video
    C MCQ: • What printf returns af...
    C Interview Questions: • Designated Initializat...
    QUICK SHORT VIDEOS
    -------------
    C++ Short : • C++ Short Videos
    C Short : • Shorts C Programming MCQ
    DESCRIPTION:
    In this video we will learn what is the actual use of smart pointers in c++.
    It is basically a wrapper which wraps raw pointer and handles the life time of the object for you, means if there is no reference to the pointer it will delete it otherwise it will hold. There are basically three types of smart pointers.
    TYPES:
    1. unique_ptr
    2. shared_ptr
    3. weak_ptr
    And the basic job of smart pointer is, it actually makes sure that we don't have memory leaks.
    #stl #cpp #programming #tutorial #interviewquestions #softwareengineering #computerscience

Komentáře • 91

  • @bhargavkumar5412
    @bhargavkumar5412 Před 4 lety +9

    Hi, I Have been learning CPP by your tutorials, your teaching is really good very understanding.
    I would like to give a suggestion where please try to explain with symbol table and memory address mapping for all the videos you do.
    Please who follows will get in-depth knowledge for sure.
    Thanks

    • @CppNuts
      @CppNuts  Před 4 lety +6

      Great suggestion!
      Will try!!

  • @zaspanyflegmatyk2446
    @zaspanyflegmatyk2446 Před 4 lety +3

    Finally I found a straight to the point nice explenation, thanks

  • @ssp8892
    @ssp8892 Před 4 lety +7

    Hello sir. Thank you very much for all the cppnuts video. I have gone through all of your uploaded cppnuts videos.Rearly all videos are very useful . I request you, could please upload the session on IPC and kernel level videos.

  • @ranjanrajesh08
    @ranjanrajesh08 Před rokem +1

    I would like to say…Thankyou Rupesh…Your video tutorials helped me crack my c++ interviews…I am a 11+ years experienced IT guy and it was difficult to crack interview at such experience with so much of technical c++ n advanced c++ questions…but you made it possible by putting variety of playlists with amazing explanations…so this channel is not just for freshers but experienced professional aa well to clear to in depth concepts in basic n advanced c++. Thanks alot again Rupesh for helping me out.

    • @CppNuts
      @CppNuts  Před rokem

      Waoo…
      It feels good that I could contribute to some meaningful.
      Thanks for such a wonderful comment.
      All the best!! Rajesh Ranjan!!

    • @ranjanrajesh08
      @ranjanrajesh08 Před rokem +1

      @@CppNuts yes Rupesh…I cracked Technical Architect role cum Technical Project Manager interview for multiple companies 😊
      Thanks alot again 🙏🏻

    • @ranjanrajesh08
      @ranjanrajesh08 Před rokem

      @@CppNuts The way you have explained how smart pointers work internally or how vectors actually work internally n many other concepts as well with so much clarity…we normally don’t get to see such content on everybody’s channel 😊

    • @CppNuts
      @CppNuts  Před rokem

      Thanks 😊

    • @softwarefoodiee
      @softwarefoodiee Před 4 měsíci

      ​@@ranjanrajesh08Hi rajesh

  • @vasukhungar2517
    @vasukhungar2517 Před 2 lety

    Best channel for c++

  • @markusbuchholz3518
    @markusbuchholz3518 Před 4 lety +2

    Perfect. Thanks for your effort and performance. It is pleasure to be here and watch your movies.

    • @CppNuts
      @CppNuts  Před 4 lety +1

      Thanks Dude, means a lot!!

  • @kitgary
    @kitgary Před 4 lety +2

    You deserve to have more subscribers! Great job! Keep it up!

  • @nijuyonkadesu
    @nijuyonkadesu Před rokem

    Dem!
    Literally, you have blown my mind!
    This made me wonder how classes can be used for our advantage....
    just yesterday, I was experimenting with pointers and was pretty disappointed by the fact that every 'new' must be paired with 'delete',
    Now this smart pointer SOLVED this problem ! wahh

  • @radhagupta5696
    @radhagupta5696 Před 3 lety

    your all the series are very helpful, i always get to know something new here from others.

  • @xuxusito
    @xuxusito Před 4 lety +1

    This is a really good channel thank you for your videos! I like the fact that you also teach new c++ features from c++11 c++17 and so on. Most Videos just teach old C++98 shit and if you are a beginner you often get stuck because you dont know that there are easy features from c++11 onwards to help you with coding.

  • @adarshverma3372
    @adarshverma3372 Před 4 lety +1

    basically what is happening
    :- if you create an object using new memory will be allocated in heap so that we have to call the delete for releasing the memory but here he is making the object of MyInt statically so the memory will be allocated in stack area and when the main function gets completed myint gets out of scoped and hence the destructor will be called.

  • @AshokKumar-mk1nr
    @AshokKumar-mk1nr Před 4 lety +1

    Really very nice explanation.. you made it as a piece of cake.. Thank you so much..

  • @oleksijm
    @oleksijm Před 4 lety

    An excellent, underrated channel.

  • @mohammedsuhailbasha4860
    @mohammedsuhailbasha4860 Před 4 lety +1

    Great explaination sir.thank you so much sir.

  • @emersoncelestial7590
    @emersoncelestial7590 Před rokem

    Hello CppNuts, I love your explanation on Smart pointers! Can I know your take on the pros and cons of using them?

  • @Al-Hebri
    @Al-Hebri Před 4 lety +2

    Thank you so much sir I`m so grateful

  • @ankitapatil5524
    @ankitapatil5524 Před 4 lety

    I really like the way you teach !!

  • @amargandhi1137
    @amargandhi1137 Před 4 lety +1

    Awesome sir appreciate viedoe on smart pointer
    Can you please provide the video on time and space complexity in data structures
    Again tysm

  • @ajayjadhav900
    @ajayjadhav900 Před 4 lety +2

    good video sir,
    can you please make video on r value reference move constructor?

  • @vvpChannel3112
    @vvpChannel3112 Před 2 lety

    Hi Rupesh sir, can you share an example to show how we can use smart pointers as templatized function pointer. This was asked in an interview.

  • @madhurimaburagohain7438

    Please make a video on noncopyable, what it is and why they are used? Thank you so much for your effort. I am enjoying your videos. Please continue making videos.

  • @abelashenafi6291
    @abelashenafi6291 Před rokem

    As always, thanks bro

  • @commentator2407
    @commentator2407 Před rokem

    i couldnt understand unique pointer's usecase
    like if we create multiple objects of a class (which holds a raw pointer), wont all of the objects point to differnt addresses in memory?
    so whats the use of unique pointers?

  • @MatheusCatarino
    @MatheusCatarino Před 4 lety +1

    Excellent explanation, but I believe it would be interesting if you can or want to subtitle your videos for a better understanding of the deaf and foreigners who do not speak English.

    • @CppNuts
      @CppNuts  Před 4 lety +1

      Sorry, that is some serious hard work, youtube should do it automatically.
      It's hard for me to even find time to record a video.
      I wish i could help in this matter.
      Thanks for the suggestion.

  • @mdshamshalam8925
    @mdshamshalam8925 Před 4 lety

    Really great all videos on smart pointers. One request can you please upload a video on one of "C++11 Features Lamba Expression in details " . Please

  • @sakthivel-mz1cz
    @sakthivel-mz1cz Před 3 lety

    Nice explantation

  • @il4w
    @il4w Před 2 lety

    Hi Rupesh could you tell me what software do you use for the drawing and explanation (i think its a virtual whiteboard software but, which one). Great work on the tutorials dude!

  • @mdirshadalam2617
    @mdirshadalam2617 Před 4 lety +1

    Hi Ruesh,
    Please explain why two times #ifdef #endif?
    #ifdef __cplusplus
    extern "C" {
    #endif
    /* Declarations of this file */
    #ifdef __cplusplus
    }
    #endif

    • @CppNuts
      @CppNuts  Před 4 lety +1

      First one is to check if it is c plus plus file and second one is to complete the breaket we started while we wrote extern c.

    • @mdirshadalam2617
      @mdirshadalam2617 Před 4 lety +1

      @@CppNuts Thanks a lot

  • @alexrcrew1975
    @alexrcrew1975 Před 2 lety

    bro is this type of concepts asked from freshers//
    although iam enjoying it but still

    • @CppNuts
      @CppNuts  Před 2 lety

      Yee it can be asked to freshers

  • @swapnilkushwah8974
    @swapnilkushwah8974 Před 4 lety +1

    finally.. awesome.

  • @vivekgr3001
    @vivekgr3001 Před 4 lety +1

    good explanation. :) the address is 1000,

  • @rupalimahajan1802
    @rupalimahajan1802 Před rokem

    where i can get these programs?

  • @veekysoft
    @veekysoft Před 3 lety

    Sir, here in main function int *p=new int(10); than we may use delete p here .....delete (data) will fine. isnt so?

    • @CppNuts
      @CppNuts  Před 3 lety

      Yes, and easy way to find is, if you see new in your program then corresponding delete also should be there, very easy way to track.

  • @srinivasthunga2468
    @srinivasthunga2468 Před 4 lety

    Hi Team,
    May i know why we need to overload dereferencing operator ?

  • @GucciJohanne
    @GucciJohanne Před 4 lety

    shouldn't it have been a templated class to be able to handle pointers of any type?

  • @gavravdhongadi9824
    @gavravdhongadi9824 Před 4 lety +1

    What role does explicit play in this role?

    • @CppNuts
      @CppNuts  Před 4 lety

      I did not use explicit for some special reason. Explicit is used only for the same reason it is used for normal cases also. Inferno what is the use of explicit keyword please Google it.

  • @teetanrobotics5363
    @teetanrobotics5363 Před 4 lety +1

    what's the use of explicit keyword ?

    • @CppNuts
      @CppNuts  Před 4 lety +1

      It is the regular use.
      I have video for what is the use of explicit keyword.

  • @vasantprabhu
    @vasantprabhu Před 4 lety

    i was searching for the 10000 :D

  • @AshokKumar-mk1nr
    @AshokKumar-mk1nr Před 4 lety

    Can you create a Linux full tutorial, like IPC, shell script,etc..

  • @mdirshadalam2617
    @mdirshadalam2617 Před 4 lety +1

    Hi Rupesh,
    What is the size of this pointer?
    How to calculate the size of this pointer?

    • @CppNuts
      @CppNuts  Před 4 lety +1

      Every pointer size is 4 bytes in 32 bit system and 8 byte in 64 bit system

    • @mdirshadalam2617
      @mdirshadalam2617 Před 4 lety +1

      @@CppNuts But empty class size is 1 byte.
      Why not 4 bytes if "this pointer" size is 4 bytes?

    • @CppNuts
      @CppNuts  Před 4 lety +1

      @@mdirshadalam2617 compile this code i have written for you, then you will understand better.
      coliru.stacked-crooked.com/a/adfc493abd8abf08

    • @mdirshadalam2617
      @mdirshadalam2617 Před 4 lety

      Thanks

  • @mapradnardev
    @mapradnardev Před 2 lety

    what is the use of explicit in constructor here?

    • @CppNuts
      @CppNuts  Před 2 lety

      explicit constructor In C++
      czcams.com/video/j4iZ50lp9KM/video.html

  • @sharwankumar-ci3hd
    @sharwankumar-ci3hd Před 4 lety

    Int & operator *() ; how to call this function and how it work could u explain me plz , thanks in advance sir

  • @akshhaayabitkaar607
    @akshhaayabitkaar607 Před 4 lety

    why constructor called explicit? and why default argument is passed as null to constuctor?
    what will happnen if i write like below--
    MyInt(int *p)
    {
    data = p;
    }
    can you please make note on constructor part here.

    • @CppNuts
      @CppNuts  Před 4 lety +1

      1 Why default is null: By doing that i made it default and copy constructor both at the same time (Its cool :D)
      2 Why constructor explicit: So that no one is allowed to assign some pointer to MyInt class.
      Example:
      int k = 10;
      MyInt i = &k; // wanted to stop this from happening
      I hope you'll get it, if not then feel free to ask more questions :D

    • @akshhaayabitkaar607
      @akshhaayabitkaar607 Před 4 lety

      got it..thank you very much.

  • @ms-hi2cc
    @ms-hi2cc Před 2 lety

    #include
    using namespace std;
    int* getStorage()
    {
    int* storage = new int[10];
    return storage;
    }
    int main()
    {
    int* storage = getStorage();

    for(int i=0;i

    • @anuj9206
      @anuj9206 Před 2 lety

      Int * storage() { int* storage
      I believe here u should use unique ptr or shared as per ur requirement
      You see
      Example say fun() {
      Int *ptr= new ptr(10) ;
      Some condition
      Return it
      }
      Say you are returning it in this function so if u won't use smart ptr(unique ptr) then it won't release the memory which has been allocated to this ptr
      That's why u should use smart ptr
      After using smart ptr
      It won't be ur responsibility to release (delete) the memory used by ptr
      Hope you get it

  • @surfaceheaven9295
    @surfaceheaven9295 Před 3 lety

    😃😃😃😃😃

  • @snehashischatterjee6820

    can you provide the code in your github?

  • @christopherapps6177
    @christopherapps6177 Před 4 lety

    The person who donot subscribe to your channel will loose lot of practical programming knowledge.... 🙂

  • @gauravganguly9395
    @gauravganguly9395 Před 3 lety

    Very nice explanation, good effort, but please give up the fake american accent next time.

  • @subhabhaskaran1827
    @subhabhaskaran1827 Před 3 lety +1

    I couldn't understand anything

  • @surajjha6029
    @surajjha6029 Před 2 lety

    bro speak in indian endglish dont try to speak foreign english