Reputation: 10153
I am implementing an abstract factory class. In the base (abstract class), I define the following typedef:
// Logging callback type.
typedef void (*LoggingCallBackFuncP)(const std::string&);
and have
static LoggingCallBackFuncP m_LogCallback;
Also I want to have following function declaration the the abstract class:
static void SetLog(LoggingCallBackFuncP callback);
This function will initialize m_LogCallback
In such a way I want to get the opportunity to initialize a log function only once and use it for all derived classes.
Is this approach OK? When/how should I initialize m_LogCallback
?
Upvotes: 0
Views: 260
Reputation: 63775
Is this approach OK?
Yes.
When/how should I initialize m_LogCallback?
Since SetLog
is static, you can call it anytime, without the need for an object instance.
The syntax is NameOfAbstractClass::SetLog( my_callback );
Upvotes: 1