Thread: argh! i dont get this!

  1. #1
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455

    argh! i dont get this!



    its making me mad now

    here is this code:

    Code:
    	curr=first;
    
    	int size=curr->resp.size(); //ERROR HERE
    	if(curr!=NULL){
    		return curr->resp[RndNum(size-1)];
    	}
    it gives an access violation error.
    lets say if i type "hello" into the prompt, itll run that peice of code., it gives this error:

    "Unhandled exception at 0x0041bd36 in aimoduletest.exe: 0xC0000005: Access violation reading location 0x00000014."
    and cites the code where the size() function of hte vector is.

    then there is this code:
    Code:
    	curr=first;
    
    	while(curr!=NULL){
    		for(int i=0;i<curr->resp.size();i++){
    			retval+=curr->resp[i];
    			retval+='\n';
    		}
    		curr=curr->next;
    	}
    that runs if you type debug into the prompt, itll return everything in that vector. i dont get why that one works, but the one above it doesnt. it returns the size fine below it, but i dunno above it
    Last edited by the Wookie; 10-11-2002 at 06:52 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Take your program and write the smallest possible toy that still exhibits the problem, then post it here and we will be happy to tell you what is causing it. I'm not fond of examples that I can't play around with to make sure that I'm right without adding huge amounts of code just to get it compiled.

    -Prelude
    My best code is written with the delete key.

  3. #3
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    ok, ill do that

    do you just want that code involved?


    heres the file:

    http://users.cloud9.net/~khalid/cAIBrain.cpp
    Last edited by the Wookie; 10-11-2002 at 07:00 PM.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >actually, ill just zip the whole thing up
    That would work, or just post a part of the file that describes the formatting.

    -Prelude
    My best code is written with the delete key.

  5. #5
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    the full thing is about 12mb, so i just added the main class file

    http://users.cloud9.net/~khalid/AIDLL.zip

  6. #6
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    a friendly little *bump*

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    There appears to be several errors in the code but I reckon the biggest error is that you are using new all over the place and not even a sniff of a std::auto_ptr. Consider what would happen if any single use of new threw an exception. Look over your use of pointers. sometimes instead of advancing the pointer you dereference it and add 1 to the pointee. If you have a 12mb project you certainly want to think about exceptions, use auto_ptr thats exactly what its there for.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    PS. Dont bump your threads here. Either you will get an answer or you wont. Live with it. If you bump threads you ........ people off and they will be less inclined to help you.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  9. #9
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    hey stoned_Coder (cool name bu the way ), what's so greate about auto_ptr. I looked it up in the help files, but all I got was that it took care of new and delete. And I'm Like: "So what".
    Plz tell me, because who knows... it might improve my code.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I looked it up in the help files, but all I got was that it took care of new and delete.
    You have fewer memory leaks, this is a big deal. But auto_ptr's have some interesting issues and aren't quite the pointer replacement we would like. However, they aren't a general smart pointer, so you shouldn't expect any more than the memory handling that they do.

    -Prelude
    My best code is written with the delete key.

  11. #11
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    if you want more general smart pointers look at boost libraries. They also have some good articles there on using auto_ptrs safely and correctly.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  12. #12
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  13. #13
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    alright thanks. sorry about the bump. all of the code files etc etc are 12mb, not the EXE

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 03-26-2003, 04:57 PM
  2. argh.... why is the percent field always 0.00?
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 02-24-2002, 06:27 PM
  3. Argh... I need help with strings = |
    By rmullen3 in forum C++ Programming
    Replies: 10
    Last Post: 01-28-2002, 07:05 PM
  4. ARGH! (argc and argv too!) HD Space!!!
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 12-05-2001, 04:05 AM
  5. argh! (argc and argv too!)
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 11-11-2001, 04:01 PM