How to Start C++ Development?
Since I encounter this question a lot lately, here's a summary of my typical answer along with some pointers.
Depends on what your goal is. C++ is certainly not dead, but better alternatives may exist, depending on your use case. Consider Go and Rust before deciding to venture forth into C++.
Still here? Alright.
First, get familiar with C. For this I recommend Beej's Guide to C Programming. Alternatively, Modern C is also a good option.
Once you are somewhat fluent with C, you may move on to C++. Or just stick with C; it's sufficient for many people and projects. Alright. Learn C++ is an excellent guide for getting into C++.
If you need technical information on a language feature or standard library component, consult C++ reference.
If you are having issues with third-party dependencies, checkout Compilation Primer.
Once you are somewhat familiar with C++, read through the C++ Core Guidelines and see what makes sense for you. This also gives you some idea on how certain language features are supposed to be used. You may also be interested in my personal opinions.
Pick up Git along the way. Strictly speaking, Git is not necessary for C++, yet any modern programmer should be familiar with Git.
Pick up a scripting language like Python or Ruby at some point as well. Certain tasks are better suited for a scripting language, knowing at least one will increase your productivity tremendously. Oh, and stay away from JavaScript!
The most important aspect is that you get your hands dirty and start building things early on. Theory is important, but practice is still paramount! Don't get stuck in Tutorial Hell.
C++ is a complex language that uses various paradigms and conventions. When wielding C++, you should understand these topics:
const
-correctnessnew
/delete
std::unique_ptr
to std::shared_ptr
Use Visual Studio Community Edition
Do not use MSYS2 or any form of MinGW. MinGW setups are a lot more error prone and not suited for beginners.
If you want to use Visual Studio with CMake (see below), always generate a Solution. Do not use File → Open → CMake... in Visual Studio as this mechanism is completely different from opening a CMake generated Solution, and much more error prone.
Install a compiler (GCC or Clang will do equally well)
sudo apt install g++
Install the CMake build system
sudo apt install cmake
Inspect the provided example project
To build and run, issue the following commands in the example folder:
cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug # only needed the first time
make -C build
./build/hello
Compiler Explorer allows you to write, compile, and run small C++ programs. You can even use third-party libraries.
Whenever you have a problem or question, create a small example in Compiler Explorer and provide a short link (top-right Share) to it along with your question.
In general, yes. A build system organizes and documents the build process and allows other tools, like IDEs, to correctly handle your project (e.g. auto-completion).
My personal preference is CMake, but Premake is also a pretty common choice.
There is a more advanced example available in example2
, featuring multiple CMake targets, tests, benchmarks, and dependencies.
For this, I recommend Advent of Code. It's an annual advent calendar where you find a programming exercises behind each day. The exercise is not specific to any programming language. You can pick exercises from past years and look up solutions on GitHub if you get stuck.
Of course you can have conversations with ChatGPT (or similar) about C++ related topics, just always be critical of the answers you get. However, AI assisted tooling should not be a part of your workflow at this point. Under no circumstances should AI be used to generate code for you.
Try to solve the issue by yourself first. Use search engines and message boards in combination with logical thinking. Only after spending some time on the problem, you are pardoned to ask for help.
Provide detailed information:
If you are dealing with a C/C++ related issue:
-Wall -Wextra
at least on GCC / Clang)-fsanitize=address
on GCC / Clang)#include
, or the compiler complaining about duplicate or unresolved symbolsIf you are having issues with an interactive application that requires various third-party dependencies: