February 01, 2003
Avoiding the Visual C++ Runtime Library
February 2003/Avoiding the Visual C++ Runtime Library
Listing 13 Constructing and destroying static class instances
class X
{
public:
X()
{}
~X()
{}
public:
void func1()
{}
void func2()
{}
};
void *operator new(size_t /* si */, void *pv)
{
return pv;
}
void operator delete (void *pv, void *)
{
}
extern "C" int __cdecl atexit(void (__cdecl *)(void))
{
// Do nothing
return 0;
}
X x; // The static instance
int APIENTRY WinMain(HINSTANCE,
HINSTANCE,
LPSTR ,
int)
{
// In-place construct, using placement new
new (&_x)X();
// the code that uses x
x.func1();
...
x.func2();
...
// Explicitly call the dtor
_x.~X();
return 0;
}
Previous Page |
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
10
|
11
|
12
|
13
|
14
|
15
|
16
Next Page