• Kajika@lemmy.ml
    link
    fedilink
    arrow-up
    7
    arrow-down
    1
    ·
    2 days ago

    I’m not sure why people keep pushing that myth on C++. It’s been a decade we have smart pointers. There’s no memory management to be done ever.

    Using the old ‘new’ is like typing ‘unsafe’ in rust. Even arrays/vectors have safe accessor.

    Am I missing something?

    • brenticus@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      2 days ago

      It’s been almost a decade since I used C++ and had to verify, but after some quick searching around it looks like it hasn’t changed a ton since I last looked at it.

      You can use smart pointers, and certainly you should, but it’s a whole extra thing tacked on to the language and the compiler doesn’t consider it an issue if you don’t use them. Using new in C++ isn’t like using unsafe in rust; in rust your code is almost certainly safe unless marked otherwise, whereas in C++ it may or may not be managed properly unless you explicitly mark a pointer as smart.

      For your own code in new codebases this is probably fine. You can just always make your pointers smart. When you’re relying on code from other people, some of which has been around for many years and has been written by people you’ve never heard of, it becomes harder to be sure everything is being done properly at every point, and that’s where many of these issues come into play.