• dylanTheDeveloper@lemmy.world
    link
    fedilink
    arrow-up
    9
    arrow-down
    1
    ·
    edit-2
    1 year ago

    As someone who switches between C++ and C and besides classes and inheriting what’s the actual difference between native C++ and C? Never really explored beyond Unreals macro heavy version of C++, wxwidgets and QT

    • Chobbes@lemmy.world
      link
      fedilink
      arrow-up
      14
      ·
      1 year ago

      C++ is technically a completely different programming language to C, but they share a lot of similarities because C++ is sort of derived from C (and now they’ve both evolved somewhat separately). The main addition at the start was OOP being baked in to C++. A typical C program is often a valid C++ program as well, but there are some subtle differences in a few areas that can cause problems. C++ has a lot of features compared to C, a more complex type system, a big templating system for compile-time computation, and focuses a lot on adding low/no cost abstractions to make writing programs easier without incurring a high cost at run-time… That said many people do still prefer C, often for its simplicity in comparison.

    • TopRamenBinLaden@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      9
      arrow-down
      3
      ·
      edit-2
      1 year ago

      C++ is a superset of C, and C is a subset of C++. C++ was originally designed for the purpose of updating and adding OOP to C.

      The main things C++ has that C doesn’t are user defined data types, support of reference variables, function overloading/overriding, built in exception handling with try/catch, inline functions, and C++ has around 30 more keywords overall.

      I would say the biggest difference is the OOP focus of C++ where all of data and functions are encapsulated into an object. This helps make C++ more secure and better for writing high level implementations than C.

      • dylanTheDeveloper@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        1 year ago

        Ahh so the whole create a object from a class thing actually works in native C++. So I can create child classes aswel and do cool stuff like casting.

        Don’t laugh okay I thought C++ through Unreal Engine was vastly different from native C++ (because that’s what I learnt first)

        Never actually used classes when I was playing with native C++. Couldn’t think of anything simple to make that would require it