I have an application that has (Qt C ++) singleton logger class. Implementation of GetInstance ():
if(m_Instance == NULL)
{
try
{
m_Instance = new Logger();
}
catch(...){}
}
return m_Instance;
Now I have the following macro in the .h file: "#define Log Logger :: Instance () → Log"
Everything is fine if a new () operation is running. What is the best way to make sure the pointer is set (I thought some try-catch blocks would catch std :: bad_alloc, but I don't know how to implement this in a macro)? I created a workaround that seems to work, but not very pretty:
"# define LOG if (Logger :: Instance ()) Logger :: Instance () → Log"
Also, I would like to know that if my object has many getters / setters (e.g. setPath (), getSize () ...)? I currently have a macro:
"# define SET Settings :: Instance ()"
SET- > setPath ( "abc" ); SET- > getSize();
, . , ?
.