blob: 3ea12a318dbed24e39292bacb251a688cbed786f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}
|