C++ is a powerful, multiparadigm language that supports procedural, object‑oriented, and generic programming. First standardized in 1998 (ISO/IEC 14882:1998), it has evolved through C++11/14/17/20/23—each revision adding modern safety and expressiveness.
Note — Why choose C++? Portability, direct hardware control, expansive ecosystems (game dev, embedded, finance), and zero‑cost abstractions that scale from microcontrollers to supercomputers.
// Small example program
#include <iostream>
int main() {
std::cout << "Hello, C++!" << '\n';
}
# Minimum viable CMakeLists.txt
cmake_minimum_required(VERSION 3.29)
project(hello LANGUAGES CXX)
add_executable(hello main.cpp)
CMake generates native project files (.ninja
, Makefiles,
Visual Studio). Pair it with conan or vcpkg for
dependency management.
Replaces the textual #include
model with binary‑interface units—reducing
compile times and ODR headaches.
// math.ixx — a module interface
export module math;
export int add(int a,int b){return a+b;}
bool
, char
, int
, double
std::int32_t
, std::uint64_t
)1'000_km
) via operator""
for (auto& v : values) { /* range‑based loop */ }
if (auto* p = std::get_if<int>(&variant); p) { /* C++17 init‑stmt */ }
Overloading, default args, inline, constexpr (compile‑time), and noexcept specifications.
constexpr int square(int x) noexcept { return x * x; }
class Image {
std::string path_;
public:
explicit Image(std::string path);
void load(); // member function
};
swap
and serialize
by convention.class Shape {
public:
virtual double area() const = 0; // pure‑virtual
virtual ~Shape() = default;
};
class Circle : public Shape {
double r_;
public:
explicit Circle(double r):r_{r}{}
double area() const override { return 3.14159*r_*r_; }
};
template<typename T>
T max(T a, T b){ return a > b ? a : b; }
template<typename T,size_t N>
class Array {
T data[N];
public:
T& operator[](size_t i){ return data[i]; }
// ...
};
template<typename T>
concept Number = std::is_arithmetic_v<T>;
template<Number T>
T add(T a,T b){ return a+b; }
#include <algorithm>
std::ranges::sort(vec); // C++20 ranges
auto pos = std::ranges::find(vec, 42);
<print>
, C++23)auto file = std::make_unique<FILE, decltype(&fclose)>(fopen(path,"r"), &fclose);
Prefer make_unique / make_shared.
Avoid naked new
/delete
except in low‑level libraries.
Polymorphic Memory Resource (<memory_resource>
) decouples containers
from allocation strategy—great for arenas or embedded systems.
#include <thread>
std::thread t([]{ heavy_work(); });
t.join();
task<void> download() {
co_await network;
co_return;
}
#include <execution>
std::sort(std::execution::par, vec.begin(), vec.end());
template<size_t N> struct fib { static constexpr size_t value = fib<N-1>::value + fib<N-2>::value; };
template<> struct fib<0>{ static constexpr size_t value = 0; };
template<> struct fib<1>{ static constexpr size_t value = 1; };
static_assert(fib<10>::value == 55);
Static reflection enables compile‑time introspection of named declarations.
match (v) {
case 0: std::println("zero"); break;
case int i if (i > 10): std::println("large"); break;
}
perf
, VTune
, Instruments
Binary package managers simplify dependency hell:
vcpkg (Microsoft), conan (JFrog),
hunter. Integrate with CMake via
find_package()
or toolchain files.
Note — Cross‑Compiling: CMake toolchain files let you target ARM, WebAssembly (emscripten), or embedded RTOS with one source tree.
constexpr
, templates, or inline functions.-Wall -Wextra -Werror -pedantic
.