P
Protoman
Here's a non intrusive reference counting smart pointer class I'm
working on; I keep getting a "22 C:\Dev-Cpp\SmrtPtr.hpp ISO C++ forbids
declaration of `SmrtPtrDB' with no type" error.
Code:
SmrtPtr.hpp
#pragma once
template<class T>
class SmrtPtr
{
public:
explicit SmrtPtr(T* obj)tr(obj)
{
DataBase.add();
for(;
{
if(isInvalid())
delete this;
}
}
SmrtPtr(const SmrtPtr<T>& rhs)tr(rhs.obj){DataBase.add()}
~SmrtPtr(){delete ptr; DataBase.sub()}
T& operator*(){return *ptr;}
T* operator->(){return ptr;}
T** operator&(){return &ptr;}
private:
static SmrtPtrDB<T> DataBase;
bool isInvalid()
{
for(;
if(!DataBase.status())
return true;
else return false;
}
T* ptr;
};
SmrtPtrDB.hpp
#pragma once
#include "SmrtPtr.hpp"
template<class T>
class SmrtPtrDB
{
public:
SmrtPtrDB():num(0){}
~SmrtPtrDB(){}
void add(){num++;}
void sub(){num--);
int status(){return num;}
private:
int num;
};
Could you help me out on this? I'm not even sure if I'm coding the
non-intrusive reference counting correctly. Thanks!!!!!
working on; I keep getting a "22 C:\Dev-Cpp\SmrtPtr.hpp ISO C++ forbids
declaration of `SmrtPtrDB' with no type" error.
Code:
SmrtPtr.hpp
#pragma once
template<class T>
class SmrtPtr
{
public:
explicit SmrtPtr(T* obj)tr(obj)
{
DataBase.add();
for(;
{
if(isInvalid())
delete this;
}
}
SmrtPtr(const SmrtPtr<T>& rhs)tr(rhs.obj){DataBase.add()}
~SmrtPtr(){delete ptr; DataBase.sub()}
T& operator*(){return *ptr;}
T* operator->(){return ptr;}
T** operator&(){return &ptr;}
private:
static SmrtPtrDB<T> DataBase;
bool isInvalid()
{
for(;
if(!DataBase.status())
return true;
else return false;
}
T* ptr;
};
SmrtPtrDB.hpp
#pragma once
#include "SmrtPtr.hpp"
template<class T>
class SmrtPtrDB
{
public:
SmrtPtrDB():num(0){}
~SmrtPtrDB(){}
void add(){num++;}
void sub(){num--);
int status(){return num;}
private:
int num;
};
Could you help me out on this? I'm not even sure if I'm coding the
non-intrusive reference counting correctly. Thanks!!!!!