noknow.dev
Sign inSign up
Course overview
C++ Fundamentals
0 / 39 lessons0%

Getting Started

  • Hello, World!
  • Variables and Data Types
  • Arithmetic and Operators
  • Working with std::string
  • Type Conversion and Casting

Control Flow

  • if / else if / else
  • switch / case
  • while and do-while Loops
  • for Loops
  • break, continue, and Finding Primes

Functions

  • Writing Functions
  • Pass by Value vs. Pass by Reference
  • Overloading and Default Parameters
  • Recursion

Arrays and Strings

  • C-style Arrays
  • std::vector — Dynamic Arrays
  • std::string Deep Dive
  • 2D Arrays and Matrices

Pointers and Memory

  • Memory Addresses and Pointers
  • Dynamic Memory: new and delete
  • References vs Pointers

Object-Oriented Programming

  • Classes and Objects
  • Constructors and Destructors
  • Inheritance
  • Virtual Functions and Polymorphism
  • Operator Overloading

The Standard Template Library

  • std::vector in Depth
  • std::map and std::unordered_map
  • std::set and Sorted Unique Collections
  • STL Algorithms

Templates and Generic Programming

  • Function Templates
  • Class Templates

Modern C++ (C++11/14/17)

  • auto and Range-based for
  • Lambda Functions
  • Smart Pointers
  • Move Semantics

Error Handling and Exceptions

  • try / catch / throw
  • Custom Exception Classes
  • RAII and Resource Management

RAII and Resource Management

0m 00s

Resource Acquisition Is Initialization

RAII is C++'s most important pattern: tie resource lifetimes to object lifetimes so cleanup happens automatically — even if exceptions are thrown:

class MutexGuard {
    mutex& mtx;
public:
    MutexGuard(mutex& m) : mtx(m) { mtx.lock(); }
    ~MutexGuard()                  { mtx.unlock(); }

    // Non-copyable — unique ownership
    MutexGuard(const MutexGuard&) = delete;
    MutexGuard& operator=(const MutexGuard&) = delete;
};

mutex m;
void criticalSection() {
    MutexGuard guard(m);   // locks
    // ... do work ...
}   // guard's destructor unlocks, no matter what

RAII in the standard library

  • unique_ptr / shared_ptr — memory
  • lock_guard / unique_lock — mutex locks
  • ifstream / ofstream — file handles

Your Task

Implement a Timer RAII class that records the start time in its constructor and provides getElapsedMs() returning elapsed milliseconds as long long.

Back
cppCtrl+Enter to run
Output

Click "Run" to execute your code.