As a total beginner to c++ I am looking for learning resources, be they books or videos.

  • laxe@lemmy.world
    link
    fedilink
    arrow-up
    4
    arrow-down
    1
    ·
    10 months ago

    I’m curious - for what purpose are you looking to learn C++?

    This was my first programming language and I have a special attachment to it but it is definitely on the decline.

    • SomeBoyo@feddit.deOP
      link
      fedilink
      arrow-up
      3
      arrow-down
      1
      ·
      10 months ago

      I have a funny project to create a cursed keyboard using a STM32F401 and their IDE happens to use c++.

    • Scrath@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      2
      arrow-down
      1
      ·
      10 months ago

      It may be on the decline but I can’t see it going anywhere in embedded any time soon. Not sure I’d want to develop for desktop with it though

  • mhredox@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    10 months ago

    Piggybacking on this:

    I’ve been wanting to learn C++ as well. I am very experienced with JavaScript, and also am very fluent with Arduino. I’ve messed around with actual C++ before but I get lost with all the pointers, header files, and memory allocation stuff.

    Are there any resources y’all would recommend to someone who has all of the programming fundamentals, but wants to learn the specifics of C++?

    • namingthingsiseasy@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      10 months ago

      My advice would be to learn C first (or at least develop a good understanding of it). It’s extremely important to understand how memory works in C so that you can understand pointers in C++; and also important to understand how functions work so you can understand classes and methods in C++. I would go through The C Programming Language. It’s fairly concise and while you don’t have to go through it cover to cover, you should at least understand the chapters on structs, pointers and functions (up to chapter 6, I believe).

      (Note that the wikipedia link that I posted above has a link to the full text of the book in pdf format.)

      The reason why I think it’s important to understand C is because when you learn C++, then you’ll understand how the language abstracts over a lot of the lower-level functionality in C. new in C++ supplants malloc in C for example, and your understanding of functions in C will map to more complicated concepts like constructors, destructors, copies, methods, and operators in C++. At this point, I would probably start learning how classes in C++ work. They’re basically structs with private member variables and methods defined in the scope of the class. learncpp.com, is the best reference that I’m aware of (it’s very thorough, which makes for a pretty slow read, but you’ll understand it very well). I would probably start with chapter 14 (introduction to classes), and then go back to the earlier chapters to fill in the gaps, but this is more dependent on how you think you learn best.

      Be aware though, that if you don’t have existing experience with OO development, then C++ is (in my opinion) not a great language to start learning it, because a lot of it is hacked on top of C and implemented in arcane ways in order to maintain compatibility with C. The first language I learned was Java, and it was really helpful to have that as a background for when I learned C/C++. I’m only familiar with Javascript on a procedural programming level, so I’m not aware of its OO functionality or how well that will translate to C++, but hopefully it works out.

      Good luck!

      • mhredox@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        10 months ago

        Thanks for the very thorough response! I will absolutely check this out. I would say I have a fair bit of experience in OO programming. A decent amount from JS and also a good bit from C#, which I dabbled in for a good while during my “I’m going to make a game in unity” phase haha.

        I know enough C++ to get myself in trouble, but it seems every time I have to use it I get super frustrated that things aren’t as simple as they are in other languages I’m familiar with. That, and I never seem to know the exact terminology to look up my particular issue (which is half the battle anyways).

        I actually needed to write a UDF in C for my mariadb instance just the other day. It ended up taking me several hours for something that would have taken me just minutes in JS or C#. It ended up being a pointer + memory allocation issue. Basically I wasn’t clearing the allocated memory and resetting the index between function calls. It also frustrates me to no end that I can’t just array.push() to add a new char to the end of a char array lol.

        I also wrote a VST with Juce in C++ a few years back. I got it working eventually, but God I remember it being an absolute nightmare.

        I guess really I have a hard time understanding when and why it’s even necessary to use pointers etc since that stuff has been abstracted away in the higher level languages I know. It seems like you could essentially get the same functionality by just knowing when things are passed by value vs passed by reference.