|
-
Feb 6th, 2002, 07:59 PM
#1
Thread Starter
Fanatic Member
classes
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
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Feb 6th, 2002, 08:14 PM
#2
Fanatic Member
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
-
Feb 7th, 2002, 07:12 AM
#3
transcendental analytic
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.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Feb 7th, 2002, 11:29 AM
#4
Thread Starter
Fanatic Member
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Feb 8th, 2002, 07:09 PM
#5
Thread Starter
Fanatic Member
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;
};
Last edited by DNA7433; Feb 10th, 2002 at 09:35 PM.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Feb 8th, 2002, 11:43 PM
#6
Make sure that you arent calling the function on an invalid pointer (you might have forgotten to create an instance of the class).
Z.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|