Created
December 3, 2012 15:13
-
-
Save Javran/4195626 to your computer and use it in GitHub Desktop.
COM mgmt test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stack> | |
#include <cstdio> | |
class Dummy | |
{ | |
public: | |
void Release() | |
{ | |
printf("remove: %p\n", this); | |
} | |
}; | |
class COMHolder | |
{ | |
public: | |
std::stack<Dummy *> comStk; | |
COMHolder() {} | |
void hold(Dummy *c) | |
{ | |
printf("create: %p\n", c); | |
comStk.push( c ); | |
} | |
virtual ~COMHolder() | |
{ | |
for ( ;!comStk.empty(); comStk.pop()) | |
{ | |
Dummy *d = comStk.top(); | |
if (d) | |
{ | |
d->Release(); | |
#ifndef COM | |
delete d; | |
#endif | |
} | |
} | |
} | |
}; | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
COMHolder h; | |
h.hold(new Dummy()); | |
h.hold(new Dummy()); | |
h.hold(new Dummy()); | |
h.hold(new Dummy()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment