I have a Logger class in my C++ application. This class has public methods like writeDebug(std::string & str)
, can write to a debug output file and it works for me very good. The object is being created on application start by the first main class and there it is stored as a Logger * myLogger;
object.
Since I have other classes as well, I would like to provide this logging functionality to those classes as well.
Currently I oberhead the myLogger pointer to toher classes in their contructor, and all the other classes store this very same Logger pointer when being created --> all other classes has this Logger * myLogger
pointer stored:
Other_XY_Class::Other_XY_Class(Logger * logger, ...)
: localLoggerPtr{logger} { //.. }
==> localLoggerPtr (in class Other_XY_Class) == myLogger (in main application class)
I can imagine that there is a more convenient / elegant way to handle that ?