• Lauchmelder@feddit.de
    link
    fedilink
    Deutsch
    arrow-up
    0
    ·
    edit-2
    7 months ago

    Why are you putting the implementation in the .h file? You’re supposed to declare in the header and implement in the .cpp files. The meme is reversed

    • Lauchmelder@feddit.de
      link
      fedilink
      Deutsch
      arrow-up
      0
      ·
      7 months ago

      The reason is that header files are pretty much copy/pasted into your c files when you include them. so the code in them keeps getting recompiled for every c file, which drastically increases overall build times. If you only declare in the header and have one c file implementing the functions you compile them only once.

      • bort@sopuli.xyz
        link
        fedilink
        arrow-up
        0
        ·
        7 months ago

        drastically increases overall build times

        oh wow. from 0ms all the way up to 0ms. That’s almost 1000 times faster wow.

      • Victor@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        7 months ago

        AI reply? That’s the point they’re trying to make. The implementation shouldn’t be in the header file, but it is. Look at the image.

        • Lauchmelder@feddit.de
          link
          fedilink
          Deutsch
          arrow-up
          0
          ·
          7 months ago

          pretty sure the meme is about how the implementation looks ugly but using the implementation looks good because all the code is abstracted away. if it was like you said then why would they compare the code to the main.cpp

    • merthyr1831@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      7 months ago

      If C++/C were real languages for real programming they’d enforce this in the compiler.

      No sane language designer would say “it is imperative that you do not implement your class in its header file” then write a compiler designer to say “oh you implemented your code in the header file? lol lmao that rocks”

      They have played you all for fools.

      • Lauchmelder@feddit.de
        link
        fedilink
        Deutsch
        arrow-up
        0
        ·
        7 months ago

        not saying it’s good design, I ditched C++ long ago. at least the C++20 modules API is gonna fix this, right guys?