Thread: Assert Debug Error??

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Question Assert Debug Error??

    I have never seen this before.
    I've read on it, but have been unable to figure out why it is occuring. It says it is an issue with my logic.

    Could someone look at my program to see if they can figure out why.

    I created list a.
    I used the = key to duplicate.
    It works fine up until i use
    (esc) to exit.
    this route it creates an access violation.

    when i read a file from a (.dat)
    next use the = key to duplicate
    then use (esc) to exit.
    the assert error occurs.

    I seem to have a destructor issue.
    when it destroys the duplicated list it seems to have an issue.

    What is creating this and how do I prevent this in the future.
    Last edited by xviddivxoggmp3; 10-18-2003 at 05:47 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    getch() returns an int not a char.

    Some special keys require you to call getch() twice to determine their value. You might want to look into that "feature" if you're planning to use getch() that extensively.

    >>linklist(linklist *); //copy constructor
    That is not a copy constructor. See my example in your other thread.

    You seem to have written a lot of code. it's about time you started debugging it
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Start the debugging with your destructor. Take a look at what you have.

    Code:
    if(head!=NULL)
    {
      current = head->next;
    
      while (current != NULL)  
      {
        x++;
        cout << "delete node " << head->lname << endl;
        delete head;
        head = current;
        current = current->next;
      }
    
      cout << "Deleting last node " << head->lname << endl;
      delete head;
    }
    else
    {
      delete head, tail;
    }
    What happens when the head pointer is null? You're trying to delete memory you never allocated. Also why do you have the head, tail business? Write them as two separate lines

    delete head;
    delete tail;

    But not in the else clause. Don't delete pointers that were never allocated!
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  4. #4
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Exclamation Assert error still there...

    I have tried multiple times to correct the error, but have been unable to correct it.

    As for the program I'm only aware of 2 bugs.
    (1) The termination (destructor) after I use the overloaded =.
    Which is why I posted this thread and this thread
    (2) My sort when merging the lists.prior thread

    I unfortunately have not picked up on any hints from other posters or enough information to research fixes for either.

    I'm fairly new to C++ so please forgive my ignorance.
    I feel my logic is sound, but according to the compiler it is not.
    >>linklist(linklist *); //copy constructor
    That is not a copy constructor. See my example in your other thread.
    I'm not sure what you mean by this. I thought the code provided was what you would call a copy constructor. Why is it not. All I see you showing me with your code is how to navigate to the locations I should input my own code. I do not see anything that would allow the calculations or processing to occur. Am I missing something?

    Doesn't the equal sign require to be overloaded? My teacher is requiring us to overload it for the project. Is this redundent and meaningless or am I again just way off the mark? He stated specifically I need to create a copy constructer and an overloaded = operator to copy the link list to another. Data only nothing more. Is this not what I did.

    Back to the errors. Is there a book that tells you a beginner version of how to write correct syntax to prevent this particular assert error. I read what was available in msvc++, but it wasn't to helpful.

    [EDIT]
    I noticed something in my research of creating a copy constructor. It stated that unless you do a deep copy the pointers copied in you class will not be valid. How do you know if this is the case? And if it is how would I fix this?
    Code:
    	linklist::linklist(linklist *Original)
    	{
    		Original->current=Original->head;
    		while(Original->current!=NULL)
    		{
    			link* newlink = new link;
    
    			strcpy(newlink->lname,Original->current->lname);
    			strcpy(newlink->fname,Original->current->fname);
    			strcpy(newlink->ssnumber,Original->current->ssnumber);
    			newlink->age=Original->current->age;
    			newlink->weight=Original->current->weight;
    
    			newlink->next = head;
    			if (head == NULL) //this tells me I have an empty list
    			{
    				head = newlink;
    				tail = head; 
    			}
    			else
    			{ 
    				head = newlink; 
    			}
    			Original->current=Original->current->next;
    		}
    	}
    wouldn't the red parts be the assignment of the new head and tails in the copied list? Wouldn't that mean I'm using addresses that would be valid? I'm trying to make sure the pointer issue mentioned earlier isn't the reason for the destructor crash. I believe that these locations should prevent invalid addresses from being assigned. Am I incorrect at assuming this?
    [/EDIT]
    Last edited by xviddivxoggmp3; 10-18-2003 at 10:54 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>linklist(linklist *); //copy constructor
    That is not a copy constructor. See my example in your other thread.

    I'm not sure what you mean by this.
    Your function prototype shows a function taking a linklist pointer as its argument. Copy constructors work by reference, you must use & not *.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    I get the errors with either code.
    Code:
     
    linklist(linklist *); //copy constructor
    or this
    Code:
    linklist(linklist &); //copy constructor
    it works the same either way. the only difference is the way i'm required to reference the member data within the function.
    it still has an access issue with the pointers used.
    how do i know the duplication is working correctly in regards to copying the correct addresses into the pointers?
    i've read that this could create an issue, and i want to make sure that isn't it.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  3. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM