CodeTheRobot

Track 01 · Beginner · Free

C++ Beginner

C++17 foundations and object-oriented programming, line by line.

Phase 1 covers the toolchain, the core language, memory and RAII. Phase 2 adds encapsulation, inheritance, polymorphism, headers and error handling: the object model that ROS 2 is built on. Every lesson uses C++17 and puts a plain-English note under every line of code.

Prerequisite: None. A laptop and a terminal are enough.

Pixel-art C++ robotics programming workbench
COMPILER READY
Track 01 · Beginner TRACK

You will be able to

  • Compile, link and debug a multi-file C++17 program
  • Use pointers, references, the stack and the heap safely
  • Design classes with RAII, inheritance and virtual functions
  • Handle errors with exceptions and std::optional

Lesson outline

01

Compilers & the build process

GCC, Clang and MSVC; what happens between source code and a running program.

45–75 minOpen lesson
02

Compilation vs linking; object files and executables

The four stages, .o object files, and why a missing definition is a linker error.

45–75 minOpen lesson
03

Basic syntax, variables and types; auto basics

Statements, int/double/bool/char, const, initialization and auto.

45–75 minOpen lesson
04

Comments, formatting and naming

// and /* */ comments, readable layout, and naming conventions used in ROS 2.

30–45 minOpen lesson
05

Input and output: std::cout, std::cin, streams

Printing, reading numbers, checking that input succeeded, and string streams.

45–75 minOpen lesson
06

Control flow: if, else and switch

Making decisions, comparing values, and the C++17 if-with-initializer.

45–75 minOpen lesson
07

Loops: for, while and do-while

Counting loops, range-based for, conditions, break and continue.

45–75 minOpen lesson
08

Functions: parameters, return types and overloading

Declaring and calling functions, default arguments, and overloads by parameter type.

45–75 minOpen lesson
09

Arrays and strings: raw arrays, std::string, std::array

Fixed-size arrays, why raw arrays are risky, and safe alternatives.

45–75 minOpen lesson
10

Pointers and references: T*, T& and passing by reference

Addresses, dereferencing, nullptr, references, and const references.

60–90 minOpen lesson
11

Memory model: stack vs heap, new/delete, and why raw pointers are dangerous

Where objects live, manual allocation, leaks and dangling pointers.

60–90 minOpen lesson
12

Structs and classes: members, methods and constructors

Bundling data and behaviour, public and private, constructors, const methods.

60–90 minOpen lesson
13

RAII: deterministic cleanup, and why ROS 2 uses it everywhere

Acquire in the constructor, release in the destructor, and stay leak-free.

60–90 minOpen lesson
14

Encapsulation

Private data, a small public interface, and class invariants.

45–75 minOpen lesson
15

Inheritance

Base and derived classes, protected members, and the 'is-a' rule.

45–75 minOpen lesson
16

Polymorphism and virtual functions

Calling the right function through a base pointer, override and virtual destructors.

60–90 minOpen lesson
17

Abstract classes and interfaces

Pure virtual functions, interface classes, and swapping real hardware for a fake.

45–75 minOpen lesson
18

Operator overloading

Giving your types +, ==, and << with clear, predictable meaning.

45–75 minOpen lesson
19

Namespaces

Avoiding name clashes, using declarations, and the ROS 2 naming style.

30–45 minOpen lesson
20

Header files and project structure

Declarations in .hpp, definitions in .cpp, include guards and folder layout.

45–75 minOpen lesson
21

Exceptions

try, catch, throw, exception types, and safe cleanup during unwinding.

45–75 minOpen lesson
22

Error handling patterns

Return codes, exceptions, std::optional results, and choosing between them.

45–75 minOpen lesson

Project examples

PRJ-01

Sensor log parser & report

Read a robot telemetry file, compute min, max and mean per joint, and print a formatted report using std::string, std::array and streams.

std::ifstream in{"joints.csv"};
double torque{};
while (in >> torque) { peak = std::max(peak, torque); }
PRJ-02

Joint limit checker class

A small class that validates target angles against per-axis limits, keeps its invariant private, and reports violations with a clear message.

class JointLimits {
public:
  bool allows(int axis, double deg) const;
};
PRJ-03

Motor interface with a fake

An abstract MotorPort interface, a simulated motor for tests, and an application function that depends only on the interface.

class MotorPort {
public:
  virtual ~MotorPort() = default;
  virtual bool command(double torque) = 0;
};

Free course

Begin when you are ready.

22 lessons · 2 phases · self-paced. Curriculum aligned with the ISO C++ reference material and verified September 2026.

ISO C++ resources