From 601442f94fc0dcfdc5a117c5f87d90b156d53045 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 31 Oct 2021 14:27:26 +0800 Subject: +static initiator --- .../StaticConstructorSample/MyClass.h | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h (limited to 'ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h') diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h b/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h new file mode 100644 index 0000000..5f86f22 --- /dev/null +++ b/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h @@ -0,0 +1,36 @@ +// MyClass.h +// +#include +#include + + +class MyClass +{ +protected: + // Declaration of protected static data members: + // Cannot be initialized here (C++ language limitation) + static void* mpStaticMemory; + static const double mPI; + static std::string mStaticStr; + +public: + // Static function members to get the static data members (to unify the Tests): + static const double& PI() { return mPI; }; + static std::string& StaticStr() { return mStaticStr; }; + +public: + // Default Constructor: + MyClass(); + + // Destructor: + virtual ~MyClass(); + + // Static Constructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in the CPP file) + STATIC_CONSTRUCTOR(); + + // Static Destructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in the CPP file) + STATIC_DESTRUCTOR(); +}; + -- cgit v1.1-26-g67d0