Assume that I have three files: A.hpp, A.cpp, B.cpp
Here's the content of A.hpp:
#ifndef CELLML_MODULES_HPP
#define CELLML_MODULES_HPP
static Cardboard *cb1; <--- assume Cardboard as a C++ generic class
...
int dummy_funct();
#endif
For the A.cpp:
#include "A.hpp"
int dummy_funct()
{
cb1 = new Cardboard();
...
cb1->doSomething();
}
Lastly, the B.cpp:
#include "A.hpp"
int main()
{
...
dummy_funct();
...
cb1->doSomething();
}
At B.cpp, cb1->doSomething got error NULL pointer, as such that the cb1 is still NULL. I've already made sure that cb1 is initialized in the dummy_funct function. Why does this happen? Is static class can be NULL even after initialization?