• MyNameIsRichard
    link
    fedilink
    arrow-up
    19
    arrow-down
    2
    ·
    6 days ago

    There’s always a destructor though. It may do nothing but it’s there.

          • MyNameIsRichard
            link
            fedilink
            arrow-up
            4
            ·
            5 days ago

            The compiler will still generate one. It won’t be any use but it will be generated :)

            • Valmond@lemmy.world
              link
              fedilink
              arrow-up
              2
              arrow-down
              1
              ·
              5 days ago

              Well no because if you allocate stuff in the constructor, you are going to write a destructor now, freeing that allocated stuff up / closing that socket, pipe whatever etc.

              Right?

              Right??

              • MyNameIsRichard
                link
                fedilink
                arrow-up
                4
                ·
                edit-2
                5 days ago

                If I do it straight after the constructor, then definitely but if I get distracted by something else then it’s only probably until I run it through valgrind and see the leak. These days, I mostly use smart pointers in new code though so there are fewer opportunities to need a destructor. It’s funny that I never forget when opening a file or db connection!

                • Valmond@lemmy.world
                  link
                  fedilink
                  arrow-up
                  4
                  arrow-down
                  2
                  ·
                  5 days ago

                  After the constructor?

                  No need for a destructir bc smart pointers?

                  Man you does not make any sense.