• lazyneet@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago

    I’ve been using C++ almost daily for the past 7 years and I haven’t found a use for shared_ptr, unique_ptr, etc. At what point does one stop being a noob?

    • riodoro1@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      3 months ago

      This guy probably still uses a char*.

      What have you been using it daily for? arduino development? I’m hoping no company still lives in pre C++17 middle ages.

    • MajorHavoc@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      3 months ago

      At what point does one stop being a noob?

      I recognize that trick question. For C++, the answer is always “soon”.

    • AngryPancake@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      Given that you probably are using pointers, and occasionally you are allocating memory, smart pointers handle deallocation for you. And yes, you can do it yourself but it is prone to errors and maybe sometimes you forget a case and memory doesn’t get deallocated and suddenly there is a leak in the program.

      When you’re there, shared_ptr is used when you want to store the pointer in multiple locations, unique_ptr when you only want to have one instance of the pointer (you can move it around though).

      Smart pointers are really really nice, I do recommend getting used to them (and all other features from c++11 forward).

      • arendjr@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        3 months ago

        Smart pointers are really really nice, I do recommend getting used to them (and all other features from c++11 forward).

        You’re recommending him to give up his sanity and/or life?