P
Protoman
OK, this code compiles, links, and executes, but, how do I setup, like,
a spinlock to query the DataBase object's status to let the SmrtPtr
know that the object's been deleted?:
#pragma once
class SmrtPtrDB
{
public:
SmrtPtrDB():num(0){}
~SmrtPtrDB(){}
void add(){num++;}
void sub(){num--;}
int status(){return num;}
private:
int num;
};
#pragma once
#include "SmrtPtrDB.hpp"
template<class T>
class SmrtPtr
{
public:
SmrtPtr<T>(T* obj=0)tr(obj){DataBase.add()
SmrtPtr<T>(const SmrtPtr<T>& rhs)tr(new
T(*(rhs.ptr))){DataBase.add();}
~SmrtPtr<T>(){delete ptr; ptr=0; DataBase.sub();}
void operator=(T val){*ptr=val;}
SmrtPtr<T>& operator=(const SmrtPtr<T>& rhs)
{
if(this!=&rhs)
{
delete ptr;
ptr(rhs.ptr);
}
else return this;
}
int status(){DataBase.status();}
T& operator*()const{return *ptr;}
T* operator->()const{return ptr;}
private:
SmrtPtrDB DataBase;
T* ptr;
};
I'm very confused. Am I implementing this right? Thanks!!!!
a spinlock to query the DataBase object's status to let the SmrtPtr
know that the object's been deleted?:
#pragma once
class SmrtPtrDB
{
public:
SmrtPtrDB():num(0){}
~SmrtPtrDB(){}
void add(){num++;}
void sub(){num--;}
int status(){return num;}
private:
int num;
};
#pragma once
#include "SmrtPtrDB.hpp"
template<class T>
class SmrtPtr
{
public:
SmrtPtr<T>(T* obj=0)tr(obj){DataBase.add()
SmrtPtr<T>(const SmrtPtr<T>& rhs)tr(new
T(*(rhs.ptr))){DataBase.add();}
~SmrtPtr<T>(){delete ptr; ptr=0; DataBase.sub();}
void operator=(T val){*ptr=val;}
SmrtPtr<T>& operator=(const SmrtPtr<T>& rhs)
{
if(this!=&rhs)
{
delete ptr;
ptr(rhs.ptr);
}
else return this;
}
int status(){DataBase.status();}
T& operator*()const{return *ptr;}
T* operator->()const{return ptr;}
private:
SmrtPtrDB DataBase;
T* ptr;
};
I'm very confused. Am I implementing this right? Thanks!!!!