Skip to content

Latest commit

 

History

History
272 lines (187 loc) · 15.4 KB

File metadata and controls

272 lines (187 loc) · 15.4 KB

C++ Language Information

Example group project from a previous CSC220 class

C++ Compiler Flags (g++)

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

C++ Tutorials

C++ References

In general, cppreference.com is a reliable C++ reference.

C++ Style Guides and Coding Recommendations

C++ Features & Topics

Vectors

Strings

Operator Overloading

Lvalues & RValues

const

Variadic Templates

Namespaces

Other Topics

Rule of Three (or 5 or Zero)

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.

Move Semantics

C++ STL

std::variant

Smart Pointers

Copy constructor vs Assignment operator (=operator)

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 + matrix2

To avoid using the copy assignment operator:

Matrix matrix1(3,4);
Matrix matrix2(3,4);
Matrix matrix3 = matrix1 + matrix2

Static Analysis

It 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

cppcheck

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

C++ History

Advanced C++

C++ Standards

C++ 11

C++ 17

C++ 20

  • Notes from the final C++ 20 standards meeting

Other

Modern C++

CppCon Back to Basics Talks

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.

2019

Link to all 2019 Back to Basics talks

2020

[Link] to a list of 2020 Back to Basics talks

Testing

Catch2

Interesting C++ Articles/Blog Posts/Papers

C++ in the Real World