Pages

Thursday, 4 March 2021

Chapter 19 // Exercise 13 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and a modified version of the std_lib_facilities header found here.

Chapter 19 // Exercise 13

Write a Tracer class where its constructor prints a string and its destructor prints a string. Give the strings as constructor arguments. Use it to see where RAII management objects will do their job (i.e., experiments with Tracers as local objects, member objects, global objects, objects allocated by new, etc.). Then add a copy constructor and a copy assignment so that you can use Tracer objects to see when copying is done.


You won't see the destructor calls for anything except the Tracer allocated by new because the rest are destroyed on return 0.

I did find out how to print line numbers in this exercise though. __LINE__ is a very handy macro. There are several others that you can use to print the file, time etc,.

No comments:

Post a Comment