Situation:
I have:
class Platform { public: Platform() { count++; cout << getCount();} static int getCount() { return count; } private: static int count; } which is created as static library.
Consider making a dynamic library extension
class __declspec(dllimport/dllexport) DerivedPlatform : public Platform { } And yes I am aware that I'm deriving from a non-dll interface class.
Per: Are static fields inherited?, there should only be a single instance of count ever.
Here's the tricky part, I actually end up with two different copies of count (even though count is declared static). Ie, upon loading in the dll and calling registerPlatforms(), it increments a DIFFERENT count object:
int main() { Platform::count = 0; Platform A; // increases count by 1, cout shows 1 loadPlugin(); // loads the shared library DerivedPlatform DerivedPlatform D; // increases count by 1 again, cout shows 2 cout << Platform::getCount(); // shows 1 !!!!!! } I have no idea how to resolve this, ie. how to ensure that only one static variable persists. Apparently DLLs have their own heap for static variables - so it sort of makes sense why this would happen.