I've implemented a Smart Pointer class, when i tried to compile, it stops on a specific line and i get this messege: Unhandled exception at 0x00418c38 in test.exe: 0xC0000005: Access violation reading location 0xfffffffc.
my code is:
template <class T>
class SmartPointer
{
private:
T* ptr;
int* mone;
public:
SmartPointer() : ptr(0), mone(0) //default constructor
{
int* mone = new int (1);
}
SmartPointer(T* ptr2) : ptr(ptr2), mone(0)
{
int* mone = new int (1);
}
SmartPointer<T>& operator= (const SmartPointer& second) //assignment operator
{
if (this!= &second)
{
if (*mone==1)
{
delete ptr;
delete mone;
}
ptr = second.ptr;
mone = second.mone;
*mone++;
}
return *this;
}
~SmartPointer() // Destructor
{
*mone--;
if (*mone==0)
{
delete ptr;
delete mone;
}
}
};
i also have a * and & overloading functions and a copy constructor.
it stops here:
if (*mone==0)
could you please help me?? thaks