Original Post
Whenever I use a class with a virtual function in my smart pointer, I get a runtime error when calling the function. Could somebody tell me why this is and how I can remedy it? Here is my smart pointer class. My program
template <class T>
class cSmtPtr{
T* ptr;
cArrayList *data;
public:
cSmtPtr() {
ptr=NULL;
data=data->GetInstance();}
T& operator*() {return *ptr;}
T& operator[](unsigned int index) {return ptr[index];}
T* operator->() {return ptr;}
void operator=(cSmtPtr<T> &temp)
{
ptr= &(*temp);
}
void New(GLint iSize=1)
{
ptr=(T*)data->New(sizeof(T)*iSize);
}
void Delete()
{
data->Delete(ptr);
ptr=NULL;
}
bool Check()
{
return data->CheckPointer(ptr);
}
void operator=(T* temp) {ptr=temp;}
};
class cBlah{
private:
int x;
public:
virtual void print()
{
cout<<"first"<<endl;
}
};
void main()
{
cSmtPtr<cBlah> b;
b.New();
b->print();
}