How to write classes in C++ and compile the codes using makefiles

Yo, computational physicists!

We've written a short introduction on how to write classes in C++, so that you can more easily structure your code projects. We highly recommend you write your codes in this way, it will simplify your life tremendously. The tutorial is hands-on and uses a simple example on how to implement a class that solves an integral numerically using the trapezoidal rule. There are certainly a lot of benefits to this approach, for instance: 

1. When you write the codes, you incrementally expand your project by adding functions to your classes so that it's easier to debug your code.
2. Generally, your code will be much easier to read and also a great deal easier to use. 

 

You'll also get an explanation on how to write a simple makefile so that compilation and execution of the codes become a simple process. 

The github repository can be found here: https://github.com/reneaas/classes_in_cpp

You can read it online or you can clone the project down to your computer. (This tutorial is aimed mostly at students using macOS or Linux. But it should also work in Visual Studio Code on Windows as well).

Cheers!

Publisert 21. aug. 2020 13:33 - Sist endret 22. aug. 2020 16:56