C
carl
I have wrapped a simple C++ logger in a class
#include "thirdPartyLogger.h"
class MyLogger {
public:
MyLogger(std::string name, int level){
// Init 3party logger with above parameters.
}
void setup(std::string name, int level) {
// the same as the constructor but necessary for construction.
}
// wrap message functions
};
Now I would like to use this logger in another class:
// .h file
class A {
public:
MyLogger logger; // works fine
MyLogger logger("A",2); // Does NOT work,
}
//.cpp file
A::A(){
logger.setup("name", 2);
}
It is not possible to create the logger using the parameterized constructor
as show above. A solution is to create the setup() function which can be
called in the constructor of A.
But is there no way to create the logger from the parameters but without
using the setup method?
I have some free template functions in a single .h file:
template<typename T>
void fun0(){
}
template<typename T>
void fun1(){
}
Now it could be nice to create the logger like this:
MyLogger logger("Free Functions",3);
and then use the samme logger instance in both the fun0 and fun1 functions.
But this is not possible. I need to call the setup function in both
functions. Any ideas?
#include "thirdPartyLogger.h"
class MyLogger {
public:
MyLogger(std::string name, int level){
// Init 3party logger with above parameters.
}
void setup(std::string name, int level) {
// the same as the constructor but necessary for construction.
}
// wrap message functions
};
Now I would like to use this logger in another class:
// .h file
class A {
public:
MyLogger logger; // works fine
MyLogger logger("A",2); // Does NOT work,
}
//.cpp file
A::A(){
logger.setup("name", 2);
}
It is not possible to create the logger using the parameterized constructor
as show above. A solution is to create the setup() function which can be
called in the constructor of A.
But is there no way to create the logger from the parameters but without
using the setup method?
I have some free template functions in a single .h file:
template<typename T>
void fun0(){
}
template<typename T>
void fun1(){
}
Now it could be nice to create the logger like this:
MyLogger logger("Free Functions",3);
and then use the samme logger instance in both the fun0 and fun1 functions.
But this is not possible. I need to call the setup function in both
functions. Any ideas?