Example group project from a previous CSC220 class
You should compile your programs with the following command to ensure you are using the correct C++ standard.
g++ --std=c++17 -pedantic -Wall filename.cpp- Google has a nice C++ Tutorial
- This 10 hour C++ Programming All-in-One Tutorial goes over most of the topics we will cover this semester
- The Cherno's C++ playlist has several short videos touching on the topics we cover in CSC240 & CSC220
In general, cppreference.com is a reliable C++ reference.
- C++ Core Guidelines (from Bjarne Stroustrup & Herb Sutter)
- Recommendations for C++ programming from Intel
- The Evil Within the Comparison Functions goes over some common mistakes when doing comparisons in C++. This is an ad for a company that sells a tool to find the mistakes, but many of the ones they list are fairly common. They also have a good list of pitfalls you can run into when writing comparisons in your code.
- A guide to Using C++ effectively on small systems
- Some good information about different implementations of std:: string
- The C++ const Declaration: Why & How
- Const Correctness from the ISO C++ website
- Const/volatile/mutable
- Practical uses for variadic templates
- C++ Insights: Variadic Templates
- Modern C++ and Variadic Functions: How to Shoot Yourself in the Foot and How to Avoid It
- VIDEO: Variadic Templates in C++11/C++14 - An Introduction by Peter Sommerlad at CppCon2015
- C++ Core Guidelines - Rules for Variadic Templates
- Everything You Need to Know About Namespace in C++
- Microsoft's documentation on Namespaces in C++
In C++ there is the idea of the "Rule of Three" - for classes that use heap memory you should implement a destructor, copy constructor, or copy assignment operator. If you want to continue in C++ it is essential knowledge.
- Video: Rule of Three in C++: Overloaded Assignment, Copy Constructor, Destructor
- C++ Made Easier: The Rule of Three
- The Rule of three/five/zero from cppreference.com
- C++ Core Guidelines: The Rule of Zero, Five, or Six
- C++ moves for people who don't NJ or care what rvalues are
- Copy vs Move semantics
- What is a move constructor in C++?
- Move Constructors and move assignment from learncpp.com
- Microsoft's introduction to Move Constructors and Move Assignment Operators (C++)
- Power up C++ with the STL (part 1) from Topcoder
- Quantcademy has a multi-part tutorial on the C++ STL, including sections on Containers, Iterators, & Algorithms
- An introduction to the Standard Template Library by Carlos Moreno
- The Complete Practical Guide to C++ STL by Abhishek Rathore
- Basic std::variant use
- Modern C++ Features - std::variant and std::visit
- A lot in information on variants from Bartek's coding blog
- std::variant Doesn't Let Me Sleep
- Exploring std::unique_ptr
- How to: Create and use unique_ptr instances from Microsoft
- Top 10 dumb mistakes to avoid with C++ 11 smart pointers
In C++, you need to be aware of what underlying operation is occurring when you set a variable. In the following case, m3 is set using =operator:
Matrix m3;
m3 = m1 + m2;In the next case below, m3 is initialized using the copy constructor
Matrix m3 = m1 + m2;You don't necessarily need the overloaded assignment operator, but adding ones let you do things like:
Matrix matrix1(3,4);
Matrix matrix2(3,4);
Matrix matrix3(3,4);
matrix3 = matrix1 + matrix2To avoid using the copy assignment operator:
Matrix matrix1(3,4);
Matrix matrix2(3,4);
Matrix matrix3 = matrix1 + matrix2It is always a good idea to run static analyzer on your code. A static analyzer is a program that analyzes your source code (without running it) and looks for potential problems. In the case of C++, it can catch many array overflows and memory management issues. They don't catch all issues (for example if a loop variable used as an array index it can still have an invalid value), so don't rely on them exclusively.
Why you should really care about C/C++ static analysis
One C++ static analyzer is cppcheck. Information about cppcheck & installation instructions are available from the cppcheck website - https://cppcheck.sourceforge.io/
I've created a video that walks you through using cppcheck on Ubuntu & using the Windows GUI.
Once your code compiles, you can run it on your code by typing:
cppcheck filename.cpp- VIDEO: The Design of C++ by Bjarne Stroustrup
- VIDEO: C++: An Invisible Foundation by Bjarne Stroustrup
- VIDEO: The Care and Feeding of C++'s Dragons is a talk about some of tools Google uses to help with simplicity in C++. It isn't really a tutorial, but it touches on a lot of issues that come up in industry.
A discussion of some obscure C++ features - C++ Annotations is an online book with a focus on differences between C & C++. It goes well beyond what we will cover this semester, but it has a lot of good information.
- VIDEO: C9 Lectures: Stephan T. Lavavej - Standard Template Library has several videos covering the STL
- John Carmack on functional programming in C++
- A list of recommended advanced C++ books
- CPPCon notes (most of the talks are available on YouTube):
- Bjarne Stroustrup's C++ 11 FAQ
- The Biggest Changes in C++ 11
- C++11 Move Constructor & Move Assignment Operator Tutorial
- Examples of changes in C++ 17
- An online book about C++ 17. Or if you want more detail - leanpub.com/cpp17
- C++ 17 lets you specify memory alignment
- Notes from the final C++ 20 standards meeting
- This blog post has a summary of what features of which standards have been implemented in different C++ compilers.
- C++ standards support in gcc
- A good interview with Bjarne Stroustrup
- An interview with Bjarne Stroustrup about his opinions of future plans for C++
- A good write up of Value Semantics in C++
- Using Modern C++ ideas with older C++ standards
- This author describes his attempt to learn C++ in 2018
- What does Modern C++ mean?
- VIDEO: Easing into Modern C++ (7 Features of C++ You Can Adopt Today)
- VIDEO: How to Adopt Modern C++17 into Your C++ Code from Build 2018
- A Guide to Modern C++ for C Programmers (there are multiple parts, the link is to the first one)
CppCon has had several good “Back to Basics” talks about a wide variety of C++ topics. Slides can be found at the CppCon links above.
Link to all 2019 Back to Basics talks
- Exception handling in C++ and making your code exception safe
- Object Oriented Programming
- RAII & the Rule of Zero This talk goes over destructors and what you need to be aware of when implementing C++ objects that allocate resources (eg. memory)
- Smart Pointers
- Move Semantics (2 parts):
- Const as a promise
- Understanding Value Categories
- Lambdas
[Link] to a list of 2020 Back to Basics talks
- The Structure of a Program
- Class Layout
- Pointers and Memory
- Smart Pointers
- Concurrency
- Exceptions
- Move Semantics
- Templates (2 parts):
- Lambda Expressions
- The Abstract Machine
- Unit Tests
- Design Patterns
- Catch2 is a unit testing framework for C++
- A Guide to using Catch2 for Unit Testing in C++
- If you are interested in networking, here is a Guide to Implementing Communication Protocols in C++
- A GameBoy emulator
- The Eudora email client source code is available from the Computer History Museum. The Windows Eudora Architecture PDF in the Widows distribution is worth reading.