|
#include <Windows.h>
#include <tchar.h>
#include <stdio.h>
#include "SmartObject.h"
class TestClass: public SmartObject
{
public:
TestClass(): SmartObject()
{
//Initialization
m_myVal=new int();
*m_myVal=1;
}
TestClass (const TestClass& b): SmartObject(b)
{
//Initialization by copying
m_myVal = new int();
*m_myVal = *(b.m_myVal);
}
TestClass & operator=(const TestClass& b)
{
if(this!=&b)
{
*m_myVal=*(b.m_myVal);
SmartObject::operator=(b);
}
return *this;
}
virtual ~TestClass()
{
if(m_myVal)
delete m_myVal;
}
void DoSomething()
{
*m_myVal=*m_myVal+1;
}
private:
int *m_myVal;
};
void SomeFunc(TestClass *sClass)
{
sClass->RetainObj();
sClass->DoSomething();
sClass->ReleaseObj();
}
int _tmain(int argc, _TCHAR **argv)
{
_tprintf(_T("Example"));
TestClass testClass;
testClass.DoSomething();
TestClass *testClass2 = new TestClass();
testClass2->RetainObj();
testClass2->RetainObj();
SomeFunc(testClass2);
testClass2->ReleaseObj();
testClass2->ReleaseObj();
delete testClass2;
while(1){}
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.