blob: a0a147c87b5701478deced293ae90c4de8b9bd37 (
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
44
45
46
47
48
|
// MyTemplate.h
//
#include <string>
#include <StaticConstructor.h>
template <typename Type>
class MyTemplate
{
protected:
// Declaration and initialization of protected static Data-Function member:
STATIC_DF_MEMBER(Type*, pStaticMemory, NULL);
public:
// Declaration and initialization of public static Data-Function members:
STATIC_DF_MEMBER(const double, PI, 3.141592);
STATIC_DF_MEMBER(std::string, StaticStr, "Init Value");
public:
// Default Constructor:
MyTemplate()
{
// PI() = 5.0; // Cannot be done, as PI is const
StaticStr() = "Modified by Default Constructor";
}
// Destructor:
virtual ~MyTemplate()
{
StaticStr() = "Modified by Default Destructor";
}
// Static Constructor:
// (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in one CPP file)
STATIC_CONSTRUCTOR()
{
StaticStr() = "Modified by Static Constructor";
pStaticMemory() = new Type[10];
}
// Static Destructor:
// (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in one CPP file)
STATIC_DESTRUCTOR()
{
delete[] pStaticMemory();
}
};
|