According to this post: global variable not exported will be only visible to its own module.
I am wondering what is the story for static variables defined inside a inline member function of a class, for example:
//cat.h
#ifdef EXPORT_ADD_
#define DLL_ __declspec(dllexport)
#else
#define DLL_ __declspec(dllimport)
#endif
Class DLL_ Cat
{
public:
static void foo()
{
static int i = 0;
std::cout << i++ << std::endl;
}
}
1) if cat.h is included in multiple module, say d1.dll, d2,dll
and Cat::foo() are called in each module
what result will be guarantee to be get?
2) it seems that __declspec(dllexport) and__declspec(dllimport)
play a important role.
In my test,
Class Cat {...} //DLL_ is removed
or
#define DLL_ //__declspec(dllimport) comment out dllimport
the static variable will not be unique
I am wondering what is the Rule of thumb to deal with static variable inside inline member functions. Thanks.