DEV Community

Cover image for How To Learn C++
Sk
Sk

Posted on • Originally published at payhip.com

How To Learn C++

I’ve been proudly learning C++ on and off for almost four years now.

after successfully seg-faulting Node.js with a node api C++ program and getting hopelessly addicted to the language, I think I’ve earned some leeway to advise on how to learn it.

C++ is a beast – metaphorically AND literally.

It’s so large that 7 days into a head-first deep dive, I’m still discovering new things. but once you learn "enough" of it, you can do some ridiculously cool stuff… with a huge chance of "shooting your leg off" in the process.


Why Learn This Beast of a Language?

It’s the bloodline of AAA games, game engines, and critical runtimes like Node.js. Want to get closer to the kernel? Embedded systems? AI can’t…👀 vibe coders can’t…

That’s power.

After years of trial and error (and the occasional distracted rabbit hole), here’s the roadmap that finally worked for me:


1. Learn C Very Well (Yes, Really)

“C compiles in C++, not the other way around.”

"C and C++ aren’t the same!" – I know.

C is simpler (not easier). C compiles in C++ – not the other way around. since C++ descends from "30-year-old C," the fundamentals transfer.

4 C Concepts to Learn:

1. The Type System

uint32_t vs. int32_t? The mysterious size_t?

2. Contiguous Memory & Buffers

 char* str = "Hello World"; 
Enter fullscreen mode Exit fullscreen mode

Your string(str) is a pointer to ‘H’.

3. Composite Types

struct person {};  
typedef struct {} person_; 
Enter fullscreen mode Exit fullscreen mode

The difference? both let you craft custom data structures.

4. System Calls

Files, network sockets, kernel events (epoll). learn these, and you’ll understand how computers actually work


2. Know Your Pointers

In C++ you get smart pointers to the rescue:

ElementPtr childPtr(inpt);  
addToParent(, std::move(childPtr)); // Ownership transferred  
Enter fullscreen mode Exit fullscreen mode

If you don’t understand raw pointers and ownership semantics, smart pointers will feel like black magic and you'll end up "shooting your leg off".

Beej’s C Guide is an excellent resource to get started with C and pointers.


3. Header Files Are Contracts

Think of header files as promises: “Hey clang(put an IDE server here), trust me—I’ll give you the real function later.”

Here’s how a clean setup looks:

Header file:

// add.h
int add(int a, int b);
Enter fullscreen mode Exit fullscreen mode

Cpp implementation:

// add.cpp
#include "add.h"
int add(int a, int b) {
  return a + b;
}
Enter fullscreen mode Exit fullscreen mode

usage:

// main.cpp
#include "add.h"

int main() {
  int sum = add(1, 2);
  return 0;
}
Enter fullscreen mode Exit fullscreen mode

Compilation:

g++ main.cpp add.cpp -o sum
Enter fullscreen mode Exit fullscreen mode

Do not include .cpp files inside other .cpp files.

Header files are how you break your project into clean, reusable parts.


4. Build Something You Care About 🫵

Tutorials are cool. But building something you actually want? That’s how you stay hooked.

Not sure what that is? Dig into that low-level itch you keep ignoring.

Purpose beats motivation, every time. you’ll debug linker errors at 3 AM for fun.


5. Make It Work → Then Make It Good

My mantra:

  1. Code it ugly

  2. Make it work

  3. Make it work well

  4. Refactor (when I’m smarter 😏)

Inspired by: Abstraction Bad? | Casey Muratori

"Premature abstraction is the root of all evil."

I Promise: It’s worth it. I’m 14 days into building my own GUI library and I’m hooked.

Bonus: Windows users – install Visual Studio 2022 or embrace WSL2. Your sanity will thank you.

You can find me here on x.

More Content
Free:

Top comments (5)

Collapse
 
sfundomhlungu profile image
Sk • Edited

For wsl2, UI is natively supported now with WSLg short for Windows Subsystem for Linux GUI.

If you know you know, we've been using xlaunch at 13 fps, wsgl is native speed!

Collapse
 
naruaika profile image
Naufan Rusyda Faikar

Oh, wow, this made me want to learn C++ sooner in the near future.

Collapse
 
sfundomhlungu profile image
Sk

I promise you. you'll not regret it! beyond the hate C++ is super powerful! the things you can do omg 🔥

Collapse
 
armando_ota profile image
Armando Ota

nice to see someone still profoundly interested in c++ .. it's been decades since i've written a program in C or C++ and loved that hard ass coding ;)

Collapse
 
sfundomhlungu profile image
Sk

Lol I am hopelessly hooked! just did 2 back to back deep work sessions, I am addicted for real.

Image description