• 0 Posts
  • 23 Comments
Joined 9 months ago
cake
Cake day: January 15th, 2024

help-circle

  • If you only care about adding numbers, you can e.g. do that using water or marbles. You only need to build an XOR gate, an AND gate and an OR gate.

    In case of water, the gate will have two inputs as water streams. They should be aligned so that when the streams hit each other, the water will flow into a cup in the center of the apparatus. When the streams don’t hit each other, the water passes the first cup and flows into another cup on the bottom. Carrying the water out at the bottom is the XOR gate, carrying the water out at the center is the AND gate and both cups together are the OR gate.

    Then it’s just about setting up the circuit and that would be a full adder without electronics.















  • AngryPancake@sh.itjust.workstoProgrammer Humor@programming.devC++
    link
    fedilink
    arrow-up
    27
    arrow-down
    1
    ·
    4 months ago

    Given that you probably are using pointers, and occasionally you are allocating memory, smart pointers handle deallocation for you. And yes, you can do it yourself but it is prone to errors and maybe sometimes you forget a case and memory doesn’t get deallocated and suddenly there is a leak in the program.

    When you’re there, shared_ptr is used when you want to store the pointer in multiple locations, unique_ptr when you only want to have one instance of the pointer (you can move it around though).

    Smart pointers are really really nice, I do recommend getting used to them (and all other features from c++11 forward).