a member function in one of my classes is returning a pointer to another class, during debugged execution it gives me an access violation on the return statement
can anyone tell me what usually causes this? thanx
Printable View
a member function in one of my classes is returning a pointer to another class, during debugged execution it gives me an access violation on the return statement
can anyone tell me what usually causes this? thanx
shouldn't be a problem i was doing the same a couple of days ago.
It did that for me when i attempted to access private members of the second class but i could pass instances of the class as parameters fine.
Then again, i'am just a newbie with C++
Gl,
D!m
this time it's obvious that Header is returning a nullpointer.
You should check either if the pointer is NULL or have a function isempty that returns true if the pointer is null, which you call when you need it, another option would be to use exceptions.
Yahoo doesn't need to be on the heap here either, make it contained.
thanks a lot
I have yet another error, of same kind though
Access Violation error when i call the Add function with AddDate = 3
You can see this time i checked to see whether pHead == NULL and that is the exact point that it gives me the error
Code:class CLinkedList
{
public:
CLinkedList( )
:mLinkCount(0), pHead(NULL)
{}
~CLinkedList( )
{
delete pHead;
}
void Add( int AddData )
{
udtLink* pTemp = new udtLink;
pTemp->Data = AddData;
if (pHead == NULL) //Access Violation occurs here
{
delete pTemp;
return;
}
pTemp->Next = pHead;
pHead = pTemp;
delete pTemp;
mLinkCount++;
}
long Count( void )
{
return mLinkCount;
}
udtLink* HeadLink( void )
{
return pHead;
}
private:
udtLink* pHead;
long mLinkCount;
};
Make sure that you arent calling the function on an invalid pointer (you might have forgotten to create an instance of the class).
Z.