⏱️Overview
This will be a quick introduction or guide to C++, listing key topics, gathering many links and how to learn, get started, and get more info.
It’s certainly not a tutorial on C++ or its syntax, since there are many already, some linked here.
🔗Links
Few links with tutorials below are covering all C++ language topics. Good for learning whole language, remembering something or latest features.
⚖️Comparisons
A good quick comparison: Differences between C C++ C#
If you know C: Compatibility of C and C++
All languages on wikipedia
A different take, showing why Object Oriented is bad.
📄Text tutorials
Good, full, C++ language tutorials and references for specific topics.
https://cplusplus.com/doc/tutorial/ – very good tutorial
https://cplusplus.com/reference
https://en.cppreference.com/w/ – very good, detailed reference, e.g.
https://en.cppreference.com/w/cpp/container/vector
rest, meh:
https://www.w3schools.com/cpp/cpp_references.asp – poor, very basic
https://www.tutorialspoint.com/cplusplus/cpp_quick_guide.htm
https://www.softwaretestinghelp.com/cpp-tutorials/
https://www.cprogramming.com/advtutorial.html
STL tutorials
STL is the C++ Standard Template Library with many template collections and algorithms. Which is the recommended approach in C++. Old way was to use new and delete to allocate memory yourself.
Good long pdf.
Very big reference pdf probably with all.
Web cpp reference for containers.
Containers with graphical visualizations here.
Tutorial with grouped short examples (e.g. map) also algorithms.
short https://takeuforward.org/c/c-stl-tutorial-most-frequent-used-stl-containers/
▶️Video tutorials
The best playlists I found to learn whole C++ from start is here and separate for concurrency.
Quite long and detailed explanations, nicely presented.
There are quite many big videos or playlists with series on youtube.
Likely not the best way to learn by just listening. Much better to read, copy code and practice.
But some topics are good to be seen in a practical session video.
E.g.: C++ Multithreading
weak_ptr and shared_ptr
For big, long e.g.
10h video – for beginners
very long – using VS code etc
advanced topics playlist but from 2017, bit outdated
🔗Links collections✨
Bigger lists of many links including libraries, books, features etc. More advanced topics too.
https://github.com/fffaraz/awesome-cpp – Frameworks, Libraries, big list e.g. for GUI, XML, and many more.
https://github.com/AnthonyCalandra/modern-cpp-features – many modern C++ features listed with examples.
https://github.com/rigtorp/awesome-modern-cpp
https://github.com/yuchdev/CppBooks
⚙️Tools around C++
General info on wikipedia
C++ has a list of software around it.
You could e.g. use Visual Studio with C++ and not know of any, like I did before.
So, if you’re on Windows and using Visual Studio, you could even skip all in this chapter. Since it has all the commercial stuff needed to build and run C++ on Windows (sure, VS can have more, but the wrong way).
Same (or even worse) goes for MacOS and using their XCode for C++ too.
But on Linux, you’ll need some effort to set up an IDE for C++, it’s likely required. Using Linux gives definitely more freedom and opportunities to learn. Additionally you can learn the Free and Open Source way, not some commercial solution.
Basic set up
Regardless any other tools later, there are some common things you’ll need to get for building projects from sources. Those can be enough to get a C++ to build and run.
But for C++ you will need a compiler like g++ (or clang, or other).
So for example, on a Debian-based Linux setup, I usually start with:
sudo apt-get install g++ binutils gdb git make cmake
But there are also other alternatives or extras like: clang ninja-build clangd etc.
CMake
CMake (wiki)- is used to configure projects, in its own language (text files). It can then generate project files for many IDEs or build tools like Make or ninja.
CMake tutorial. CMake is a step up to learn for sure, but for me the main advantage is that I don’t bother with IDEs or OSes, I edit one configuration and can build for more later.
Compilers
Compilers (bigger list) – just few main for example:
Dependency and libraries resolving
Conan – software package manager for C and C++
vcpkg – similar, but MS tool
More listed here.
Tools, memory
Valgrind – memory debugging, leaks etc
Cppcheck – static code analysis
📊IDEs
Wiki with Integrated Development Environments (IDEs) comparison here.
I list here few, biggest IDEs, my favorites that I’ve used for C++.
VS Code
Not recommended, the MS version with telemetry and such. Available on Ubuntu, but not e.g. on Debian since it’s not fully FOSS.
Good comparison between VS Code and VSCodium here and here.
VSCodium
Recommended, pure FOSS version, without telemetry and MS stuff. Available on many OSes.
To install, get a release archive and unpack. E.g. for desktop Linux name starting with VSCodium-linux-x64-
Definitely needs some more effort to set up for C++, unlike other IDEs.
My list of extensions that I use with it.
Favorite extensions
- C++ by Microsoft – only in VS Code
- clangd by llvm-vs-code-extensions – C/C++ completion, navigation, and insights – in VSCodium
- CodeLLDB by vadimcn – a native Debugger for C++
- Native Debug by webfreak – for gdb and lldb
- CMake by twxs – language support
- CMake Tools by ms-vscode – Extended CMake support, configurations etc, on status bar
- Git History Plus by cweijan – for git log, history view
- Bookmarks by alefragnani – bookmark lines
- Project Manager by alefragnani – To save folders with projects in list
- Favorites Manager by oleg-shilo – Tab with list of files, can be edited in file
- Todo Tree by Gruntfuggly – gathers all todo, fixme etc from files, in own tree list
- Output colorizer by IBM – for colors in .log files etc
- Python by ms-python – for syntax and running .py scripts
- XML by redhat – for its syntax
- Black Violet Blue by Crystal Hammer – naturally, my theme
Qt Creator
I used it for a year or so, it was easy to set up on Linux and get going for C++ with CMake (included).
So I can still recommend it.
It works very fast, but is rather limited in options, and not many extensions available. Meaning you could find something missing.
Also it can be seen as a commercial for Qt solutions, which I don’t recommend. They are too big and too Qt specific. For my smaller projects this was way too much, and also the longer you use e.g. Qt GUI for C++ the more effort it will need to move to other library.
Visual Studio (VS)
Commercial, huge (7GB or more) and bloated. I can’t recommend.
I used it for years at work and earlier myself on Windows too.
I think it’s still the way to go on Windows. Sure it works, but that’s it, can’t think of privacy or sources or freedom.
Comes with a big installer too, where you need to have some idea of what components to install. IIRC C++ wasn’t even selected in recent versions.
Has many extensions and themes. But for my favorite scroll plugin, each VS version had to have own support and own author which was inconsistent and annoying (for developers probably too).
It has other languages like C#, but for me now it feels like a commercial hub for MS solutions, also with news feed for it and paid stuff.
Also one major issue is that if you use Visual Studio and MS products you get (shoehorned) into their way and if you stick too long you’ll less likely or have more issues getting . And their way is definitely the one giving them most profits, not (necessarily) you.
KDevelop
I didn’t use it, but quickly looked at this IDE and it seems quite decent. Has features that every IDE should have. I just don’t see any IDE theme to turn it black fast after installing.
Eclipse CDT
I used it before I knew VSCodium for a year. I can’t recommend it, since it is based on Java (and was mainly for it at start I think) but it is just too universal and generic as VS. Only difference it has some packages specific to development needs. Small to install but slower at working. Not too many new fancy extensions.
📂File types
Header files
File extensions
Headers .h or .hh .hpp .hxx Sources .cpp or .cc .cxx .c++
Compiling .cpp gives output files:
Windows .obj Linux .o
Dependencies
It is good practice to split code into libraries.
The worst way would be to include all sources together and it would take the longest to build.
Splitting functionality to libraries speeds up whole build (if you don’t change library code) and hides the implementation.
Libs – static libraries
Windows .lib Linux .a
To compile your program (or library), the .h headers from library are need to be included.
Library’s compiled code must be linked (.lib or .a) with your program (or library).
There are also some header only libraries, which don’t need linking.
DLLs – dynamic libraries
Windows .dll Linux .so
To use DLLs, also .lib files and header files .h are needed.
Additionally binary (.dll or .so) files are needed when starting your program
(executable is .exe on Windows, and no extension on Linux, but has x attribute(s)).
C++ key concepts
A few inner concepts, some quite different from other languages.
- Header files, e.g. here,
A different special case of precompiled header (pch). - Preprocessor and other tutorial page
- Variable types, constants and type casting
- Operators also with their precedence at end (another reference on that)
- Overloads and templates
- Pointers also at end pointer to functions, and references
- Lambdas
C++ with CMake
⚙Basic example
The simplest example, for start and a way of checking if it all builds and works.
It has 2 files:
- CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(main CXX)
add_executable(main main.cpp)
- main.cpp
#include <iostream>
using namespace std;
int main()
{
int i = 10;
i += 2;
cout << "Hello. " << i << endl;
}
When started, it should print out on console: Hello. 12
C++ starter projects
Good templates for starting C++ projects with CMake and other config files e.g. for formatting, unit tests etc.
https://github.com/TheLartians/ModernCppStarter
https://github.com/filipdutescu/modern-cpp-template