Introduction
|
C++ is a compiled language, source code is translated by the compiler to machine specific binaries.
Well written C++ can achieve very high performance.
Using the compiler on the command line I can simple and run a simple C++ program.
|
Core Syntax and Types
|
|
Arrays and Vectors
|
C++ can assign fixed sized collections as arrays.
C++ can manage variable sized collections as vectors of objects.
For vectors, data elements can be added and removed, as well as updated.
|
Basic C++ operators
|
Be careful with increment operators, which have a left-side and a right-side version.
Prefer using explicit parentheses over relying on complex precedence rules.
There is no predefined power operator.
|
Compound datatypes
|
|
Functions
|
Const references avoid the cost of the copy for input arguments.
You should not be afraid any more of returning big results.
You should not be afraid any more of returning a bunch of results.
|
References
|
|
Control Instructions
|
|
Headers and Interfaces
|
Preprocessor directives are useful for making compile-time decisions
By separating header files and implementation files we can program to interfaces, not implementations.
|
Templates
|
There are function and class templates.
Template parameters can be types or integers known at the compile time.
This is all managed at compile time.
All the code must stay in header files.
Beware of code bloat.
Specialization enable to handle special parameter values, but also imply some hassle, especially when mixing templates with inheritance or implicit conversions.
Before C++20, there is no simple way to define constraints on the allowed values for template parameters.
|
Type inference
|
The new keyword auto avoid you the error-prone typing of complex long type names.
A collateral benefit is that the code is more generic.
Yet, do not overuse auto , because the types contribute to the readability of the code.
|
Classes
|
|
Sum types
|
|
Code inclusion
|
|