Skip to the content ForoHackers
Log inJoin

C++: start here

C++
#545 · Ophuscado · · Report

C++ extends C with classes, templates and a large standard library while keeping control of memory and cost. It is used where performance and resources matter: game engines, browsers, databases, trading systems and embedded software. It is a big language with several styles, and modern practice is to avoid the raw, C-like ways of managing memory.

Key concepts

  • RAII: resources such as memory, files and locks are owned by objects and released when they go out of scope.
  • Value semantics: copying, moving and ownership are explicit, with constructors, destructors and move operations.
  • Templates and generic programming: code written once for many types, resolved at compile time.
  • Standard library: containers, algorithms, strings and smart pointers, which replace most hand-written code.
  • Classes and polymorphism: inheritance and virtual functions for runtime dispatch, used with restraint.
  • Zero-cost abstraction: you do not pay for features you do not use.

Vocabulary

  • Smart pointer: an object that owns heap memory and frees it automatically.
  • Move semantics: transferring a resource instead of copying it.
  • Undefined behaviour: code the standard gives no meaning to, as in C.
  • Header and translation unit: how declarations are shared and compiled.

What to study, in order

  1. Basic C++ with the standard library: strings, vectors and maps, with no raw new or delete.
  2. Classes, constructors, destructors and RAII; write a small resource-owning class.
  3. Copy and move rules, and why smart pointers usually replace raw pointers.
  4. Templates: write a generic container and a function template.
  5. Standard algorithms and iterators; replace hand-written loops with them.
  6. Build a larger project with a build tool, warnings on and sanitisers enabled.

Related tags

#c #rust #memory-management #game-development

Log in or join to reply.