summaryrefslogtreecommitdiff
path: root/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-31 14:27:26 +0800
committerchai <chaifix@163.com>2021-10-31 14:27:26 +0800
commit601442f94fc0dcfdc5a117c5f87d90b156d53045 (patch)
treeb006bcd6a28a965a900c64f4716007fcb45eee98 /ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp
parent26f05c6e3dcac9995345fb5a2b031be7e3ea79e9 (diff)
+static initiator
Diffstat (limited to 'ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp')
-rw-r--r--ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp b/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp
new file mode 100644
index 0000000..3ea12a3
--- /dev/null
+++ b/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp
@@ -0,0 +1,43 @@
+// MyClass.cpp
+//
+#include "stdafx.h"
+#include "MyClass.h"
+
+
+// Initialization of protected static data members:
+void* MyClass::mpStaticMemory = NULL;
+const double MyClass::mPI = 3.141592;
+std::string MyClass::mStaticStr = "Init Value";
+
+
+// Invoke the StaticConstructor & StaticDestructor of the class:
+// Make sure you put this AFTER the initialization of the static data members!
+INVOKE_STATIC_CONSTRUCTOR(MyClass);
+
+
+// Default Constructor:
+MyClass::MyClass()
+{
+// PI = 5.0; // Cannot be done, as PI is const
+ mStaticStr = "Modified by Default Constructor";
+}
+
+// Destructor:
+MyClass::~MyClass()
+{
+ mStaticStr = "Modified by Default Destructor";
+}
+
+// Static Constructor:
+void MyClass::StaticConstructor()
+{
+ mStaticStr = "Modified by Static Constructor";
+ mpStaticMemory = new double[10];
+}
+
+// Static Destructor:
+void MyClass::StaticDestructor()
+{
+ delete[] mpStaticMemory;
+}
+