What I did for now was to
call/invoked
it inside of the
first line of one of any
constructor
,
Note: upon by doing it we need to have a
delegated constructor
if we do had
multiple overloaded constructors
, so that we could link it together, then put this
static block to the
last linked constructor to had a chance running it only once and will be invoke first before any other else. But first we do need to add a
static
keyword found at the header file:
static_init_block.h
3rd to the last line which is a
STATIC REGISTRATION MACRO,
#define __STATIC
static StaticInitBlock __UNIQUE(block) = [&]() -> void
PS: I did not try/implement it yet to the bigger projects, but we had an assumption that this will cause an overhead more specifically at the delegated constructor(s);
//REM: overview or in theory
class ClassOne {
public:
ClassOne() {
__STATIC {
std::cout << "ClassOne, STATIC init block" << std::endl;
};
}
};
//REM: Overloaded Constructor, I use delagation constructor
class ClassOne {
public:
ClassOne() : ClassOne(0) {
}
ClassOne(int param0) {
__STATIC {
std::cout << "ClassOne, STATIC init block" << std::endl;
};
}
};
If we want simulated/similar to
init-block
then add this line/syntax:
#define __INIT StaticInitBlock __UNIQUE(block) = [&]() -> void
at the header file which was next to the other defined
STATIC REGISTRATION MACRO
.