Results 1 to 6 of 6

Thread: classes

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  2. #2
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    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
    Dim

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    thanks a lot
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    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.

  6. #6
    Zaei
    Guest
    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
  •  



Click Here to Expand Forum to Full Width