C++
Overview
C++ is a statically typed, compiled systems programming language offering low-level control and high performance alongside high-level abstractions (classes, templates, the standard library) with a zero-overhead philosophy. It is standardized by ISO/IEC JTC1/SC22/WG21, with C++23 the most recent published standard and C++26 in progress. Read this when writing performance-critical native code, managing manual resources, or setting up a C++ toolchain.
Official sources
Install / setup
C++ has no single installer; you install a compiler. The official ISO C++ "Get Started" page lists free compilers including GCC (g++), Clang, and Visual C++ Community. Typical install of GCC on Debian/Ubuntu:
sudo apt install g++
Source / recommended compilers: https://isocpp.org/get-started
Core concepts
- RAII (Resource Acquisition Is Initialization) — tie resource lifetime to object scope so destructors release resources deterministically.
- Value semantics and the rule of move — objects are copied by default; move semantics (
std::move, move constructors) transfer ownership efficiently.
- Templates and generic programming — compile-time polymorphism over types; the STL (containers, algorithms, iterators) is built on them.
- Smart pointers —
std::unique_ptr and std::shared_ptr express ownership and automate deallocation, replacing raw new/delete.
- The standard library — containers (
vector, map), algorithms, strings, and ranges (cppreference is the canonical reference).
- Undefined behavior — the standard leaves some operations (out-of-bounds access, signed overflow, use-after-free) with no defined meaning.
Best practices
- Prefer RAII and smart pointers over manual
new/delete to avoid leaks and double-frees (per the C++ Core Guidelines, linked from isocpp.org).
- Use standard-library containers and algorithms instead of hand-rolled loops and C arrays.
- Pass large objects by
const&; use move semantics to avoid needless copies.
- Compile with warnings on (
-Wall -Wextra) and target a recent standard (e.g. -std=c++23).
Common pitfalls
- Dangling pointers/references from use-after-free or returning references to locals → use smart pointers and value semantics; this is undefined behavior.
- Out-of-bounds container/array access → undefined behavior; use bounds-checked access (
.at()) or std::span/ranges where appropriate.
- Manual memory management with raw
new/delete leaking on early return/exception → use unique_ptr/shared_ptr and RAII.
Examples
#include <memory>
#include <string>
#include <iostream>
struct Greeter {
std::string greet(const std::string& name) const {
return "Hello, " + name;
}
};
int main() {
auto g = std::make_unique<Greeter>(); // RAII: freed automatically
std::cout << g->greet("ada") << '\n';
}
Further reading
Related skills
- ../swift — a memory-safe systems language that interoperates with C/C++
- ../scala — managed-VM language for contrast with native compilation
1---2name: cpp3description: High-performance, statically typed systems language with zero-overhead abstractions; consult for C++ syntax, RAII, and setup.4domain: language5category: language6tags: [cpp, systems, performance, native, compiled]7official_sources:8 - https://en.cppreference.com/9 - https://github.com/cplusplus/draft10verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/cpp13---1415# C++1617## Overview18C++ is a statically typed, compiled systems programming language offering low-level control and high performance alongside high-level abstractions (classes, templates, the standard library) with a zero-overhead philosophy. It is standardized by ISO/IEC JTC1/SC22/WG21, with C++23 the most recent published standard and C++26 in progress. Read this when writing performance-critical native code, managing manual resources, or setting up a C++ toolchain.1920## Official sources21- Docs (community reference): https://en.cppreference.com/22- Repo (standard draft sources): https://github.com/cplusplus/draft23- Get started: https://isocpp.org/get-started2425## Install / setup26C++ has no single installer; you install a compiler. The official ISO C++ "Get Started" page lists free compilers including GCC (`g++`), Clang, and Visual C++ Community. Typical install of GCC on Debian/Ubuntu:2728```bash29sudo apt install g++30```3132Source / recommended compilers: https://isocpp.org/get-started3334## Core concepts35- RAII (Resource Acquisition Is Initialization) — tie resource lifetime to object scope so destructors release resources deterministically.36- Value semantics and the rule of move — objects are copied by default; move semantics (`std::move`, move constructors) transfer ownership efficiently.37- Templates and generic programming — compile-time polymorphism over types; the STL (containers, algorithms, iterators) is built on them.38- Smart pointers — `std::unique_ptr` and `std::shared_ptr` express ownership and automate deallocation, replacing raw `new`/`delete`.39- The standard library — containers (`vector`, `map`), algorithms, strings, and ranges (cppreference is the canonical reference).40- Undefined behavior — the standard leaves some operations (out-of-bounds access, signed overflow, use-after-free) with no defined meaning.4142## Best practices43- Prefer RAII and smart pointers over manual `new`/`delete` to avoid leaks and double-frees (per the C++ Core Guidelines, linked from isocpp.org).44- Use standard-library containers and algorithms instead of hand-rolled loops and C arrays.45- Pass large objects by `const&`; use move semantics to avoid needless copies.46- Compile with warnings on (`-Wall -Wextra`) and target a recent standard (e.g. `-std=c++23`).4748## Common pitfalls49- Dangling pointers/references from use-after-free or returning references to locals → use smart pointers and value semantics; this is undefined behavior.50- Out-of-bounds container/array access → undefined behavior; use bounds-checked access (`.at()`) or `std::span`/ranges where appropriate.51- Manual memory management with raw `new`/`delete` leaking on early return/exception → use `unique_ptr`/`shared_ptr` and RAII.5253## Examples54```cpp55#include <memory>56#include <string>57#include <iostream>5859struct Greeter {60 std::string greet(const std::string& name) const {61 return "Hello, " + name;62 }63};6465int main() {66 auto g = std::make_unique<Greeter>(); // RAII: freed automatically67 std::cout << g->greet("ada") << '\n';68}69```7071## Further reading72- Language and library reference: https://en.cppreference.com/73- ISO C++ home and Core Guidelines: https://isocpp.org/get-started7475## Related skills76- ../swift — a memory-safe systems language that interoperates with C/C++77- ../scala — managed-VM language for contrast with native compilation