C++

open, GitHub.io, 2024

This course is to become familar with C++.

C++

Sr.NoTopicsSlides 
1C++ Introduction: comments; preprocessing directive; whitespace; structure of function; input and output streams; std namespace; escape sequences; initialization; insertion and extraction operator; arithmetic, relational, and logical operator; if statement; input/output manipulators boolalpha and noboolalpha; string class; syntax and logical errors2_intro 
2Control Statements: selection statements if, if-else, switch; iteration statements while, do-while, for, range based for; conditional operator; prefix and postfix operators; nested control statements; controlling iterations with counter and sentinel value; using std locale; mixed expression; formatting floating point numbers using iomanip; using super sized integer with boost3_control 
3Control Statements: counter-controlled iteration using while and for; text formatting using std format; floating point approximation; representational error; counter controlled do-while; sentinel controlled while with end-of-file; switch-case; break; fallthrough; if with initializer; switch with initializer; break; continue; logical operator; operator precedence; equality and assignment; yoda condition4_control 
4Functions: using functions from cmath; defining functions; comma operator; argument coercion; narrow_cast using gsl; generating random numbers; digit separator; scoped enum; using enum; inline functions; passing arguments by value and reference; using const reference; avoiding dangling references; treating warnings as errors; function overloading; name mangling; function templates; recursion; global scope; unary scope resolution operator5_functions 
5Arrays, Vectors, Ranges, and Functional-Style Programming: fixed size array and resizable vectors; static array; initialization array; class template argument deduction; range-based for; external and internal iteration; const and constexpr; multi dimensional arrays; programming styles procedural, object oriented, generic, and functional style programming; passing functions as arguments; ranges and views; lazy valuation using std::views::iota; filter and transfom using views; creating pipeline of views; vector; at; exception; iterator; push_back; emplace_back; clear; erase single or range; pop_back6_arrays_vectors 
6Pointers7_pointers 
  • C++ How to Program: An Objects-Natural Approach, 11/e by Paul Deitel & Harvey Deitel
  • The C++ Programming Language (4th Edition) by Bjarne Stroustrup, Addison-Wesley

C++ Installation

# install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# install cmake
brew install cmake

# install catch2
brew install catch2

brew install boost

brew --prefix boost # get path
{
    "editor.fontSize": 24,
    "terminal.integrated.fontSize": 24,
    "editor.wordWrap": "on",
    "workbench.colorTheme": "Default Light Modern"
}
  • Set C++ 20 in the VS Code
  • Command + Shift + P > C/C++: Edit Configurations (JSON)
"cStandard": "c23",
"cppStandard": "c++23"
  • Install GSL: Guidelines Support Library, https://github.com/Microsoft/GSL
  • Command + Shift + P > C/C++: Edit Configurations (JSON)
"includePath": [
	"${workspaceFolder}/**",
	"${env:HOME}/soft/GSL/include",
  "/usr/local/opt/boost"
],
  • Use the below command to compile
clear && g++ -std=c++20 -I$HOME/soft/GSL/include main.cpp && ./a.out
  • Convert C++ Warnings to Errors for safety
clear && g++ -std=c++23 -Werror main.cpp && ./a.out
  • check name mangling for overloading
nm a.out
nm a.out | c++filt #c++ nmames

C++ Core Guidelines