Home Forums Gamescan Chat42 About
* Login   * Register * FAQ    * Search
It is currently Mon 11-17-2025 9:34AM

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Gah, error when I exit Visual C++ program (pointers?)
PostPosted: Wed 02-02-2005 10:17PM 
Offline
Colonel
User avatar

Joined: Fri 08-22-2003 9:55AM
Posts: 960

Source: TJ North
Alright, my program works fine up until I close it out. It then throws a fit that I presume to be a heap overflow, but I hardly know anything of the sort.

"Unhandled exception at 0x7c176cfa (mfc71d.dll) in demo2.exe: 0xC0000005: Access violation reading location 0xccccccc8." The error points to a line in Demo2.CPP, which is not even code I wrote.

Code:
   if (nResponse == IDOK)
   {
      // TODO: Place code here to handle when the dialog is
      //  dismissed with OK
   }
   else if (nResponse == IDCANCEL)
   {
      // TODO: Place code here to handle when the dialog is
      //  dismissed with Cancel
   }

   // Since the dialog has been closed, return FALSE so that we exit the
   //  application, rather than start the application's message pump.
   return FALSE;


I assume I've got a problem involving pointers, but I'm so sketchy on the subject, I have no idea where to find it.

I'll pm my code to anybody that thinks they can help me out.

_________________
http://www.jestmag.com/3-5/banana.html


Top
 Profile  
    
 Post subject:
PostPosted: Wed 02-02-2005 11:16PM 
Offline
Brigadier General

Joined: Tue 01-22-2002 12:35PM
Posts: 1057
Location: Shawnee Mission, KS

Source: Off Campus
If you're running it through the Visual Studio debugger, after it's gone through the dialogs telling you it's crashed, but before you actually terminate it, do an Alt-7 to bring up the call stack. Look in there for functions that you've written or have code in. You can double click on a function in the call stack to jump to it and see its local variables.

Other than that, here are some basic ideas:

Make sure you call delete on every pointer that you've used new on.

If you've used new to allocate an array, like this:

int *p = NULL;
p = new int [10];

you must use delete like this:

delete [] p;

If you just say delete p; then Bad Things (tm) can happen.

Make sure you haven't walked off the end of an array somewhere. If you're using raw character pointers (char *'s and char []'s ) this can easily happen. Sometimes, walking off the end of an array doesn't produce an immediate crash; the crash happens when you return from the function you did this (called "smashing the stack").


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Wed 02-02-2005 11:51PM 
Offline
Colonel
User avatar

Joined: Fri 08-22-2003 9:55AM
Posts: 960

Source: TJ North
Thanks for the input, but that didn't seem to do the trick. For some reason it won't let me put the destructor in the functions.cpp file, so I have to put it in the class definition header file. I don't think this would solve the problem but still a strange occurence.

I get this error:
Linking...
payroll.obj : error LNK2005: "public: __thiscall Payroll::~Payroll(void)" (??1Payroll@@QAE@XZ) already defined in demo2.obj
Debug/demo2.exe : fatal error LNK1169: one or more multiply defined symbols found

I don't have it defined twice, so no idea where thats coming from.

_________________
http://www.jestmag.com/3-5/banana.html


Top
 Profile  
    
 Post subject:
PostPosted: Thu 02-03-2005 12:07AM 
Offline
Captain
User avatar

Joined: Mon 05-07-2001 2:31PM
Posts: 180
Location: Houston, TX

Source: Off Campus
midgey wrote:
Thanks for the input, but that didn't seem to do the trick. For some reason it won't let me put the destructor in the functions.cpp file, so I have to put it in the class definition header file. I don't think this would solve the problem but still a strange occurence.

I get this error:
Linking...
payroll.obj : error LNK2005: "public: __thiscall Payroll::~Payroll(void)" (??1Payroll@@QAE@XZ) already defined in demo2.obj
Debug/demo2.exe : fatal error LNK1169: one or more multiply defined symbols found

I don't have it defined twice, so no idea where thats coming from.


check your includes.

_________________
chem^ten
a.k.a hardcore
03-04 4NW RA


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 02-03-2005 12:37AM 
Offline
Colonel
User avatar

Joined: Fri 08-22-2003 9:55AM
Posts: 960

Source: TJ North
nope, includes are correct as far as I can tell...
payroll.h doesn't have any includes

payroll.cpp has:
#include"stdafx.h"
#include"payroll.h"

_________________
http://www.jestmag.com/3-5/banana.html


Top
 Profile  
    
 Post subject:
PostPosted: Thu 02-03-2005 9:07AM 
Offline
Major
User avatar

Joined: Fri 10-25-2002 1:08PM
Posts: 356
Location: St. Louis, MO

Source: Fidelity
Are you using macro guards in your header file(s)?
Code:
#ifndef MY_HEADER_FILE  (this name must be unique for each header)
#define MY_HEADER_FILE  (same name as above)

// header code

#endif


Top
 Profile  
    
 Post subject:
PostPosted: Thu 02-03-2005 12:21PM 
Offline
Colonel
User avatar

Joined: Fri 08-22-2003 9:55AM
Posts: 960

Source: TJ North
yep, using macro guards...
looks like i'll be turning this one in late

_________________
http://www.jestmag.com/3-5/banana.html


Top
 Profile  
    
 Post subject:
PostPosted: Thu 02-03-2005 12:34PM 
Offline
Major
User avatar

Joined: Fri 10-25-2002 1:08PM
Posts: 356
Location: St. Louis, MO

Source: Fidelity
I have not read the article, but this may help.
http://www.codeproject.com/buglist/linkererrors.asp


Top
 Profile  
    
 Post subject:
PostPosted: Thu 02-03-2005 3:55PM 
Offline
Brigadier General

Joined: Tue 01-22-2002 12:35PM
Posts: 1057
Location: Shawnee Mission, KS

Source: Off Campus
midgey wrote:
Thanks for the input, but that didn't seem to do the trick. For some reason it won't let me put the destructor in the functions.cpp file, so I have to put it in the class definition header file. I don't think this would solve the problem but still a strange occurence.

I get this error:
Linking...
payroll.obj : error LNK2005: "public: __thiscall Payroll::~Payroll(void)" (??1Payroll@@QAE@XZ) already defined in demo2.obj
Debug/demo2.exe : fatal error LNK1169: one or more multiply defined symbols found

I don't have it defined twice, so no idea where thats coming from.


If you're defining it in your .h file, try putting the keyword
inline
before the definition.

Something like...
class Demo
{
public:
Demo();
~Demo();
//etc. etc.
};

inline
Demo::~Demo()
{
//destructor code goes here
}

You can also do something like
class Demo
{
public:
Demo();
~Demo()
{
//destructor code goes here
//note that when you define functions this way the semicolon goes after
//the curly brace that ends the function. No semicolon goes after the
// "~Demo()"
};

};

However, from a style standpoint, when you have inline functions it's usually better to put them at the end of the .h file (using the first tecnique). The reason is that the class declaration's purpose for humans is to say what the class does. The definitions' purpose is to say how the class does it. Good C++ coding standards seperate what a class does from how the class does it. Said another way, it seperates the interface from the implementation.


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 02-03-2005 6:51PM 
Offline
Colonel
User avatar

Joined: Fri 08-22-2003 9:55AM
Posts: 960

Source: TJ North
thanks for all the help guys. I managed to work the problem out. I scrapped the program and rewrote everything after looking at that error for more than 3 hours. Kinda sucks that I wasted so much time on it, but oh well, I should now at least be able to get a grade. Thanks again.

_________________
http://www.jestmag.com/3-5/banana.html


Top
 Profile  
    
 Post subject:
PostPosted: Fri 02-11-2005 12:20AM 
Offline
dell bitch
User avatar

Joined: Thu 06-26-2003 6:38PM
Posts: 449
Location: The Kablaamdom

Source: Kelly Hall
midgey wrote:
thanks for all the help guys. I managed to work the problem out. I scrapped the program and rewrote everything after looking at that error for more than 3 hours. Kinda sucks that I wasted so much time on it, but oh well, I should now at least be able to get a grade. Thanks again.


It's odd how often that works... but I generally just start from the top as if I was coding it rather than retyping everything. Heh.

_________________
http://jbworksit.ytmnd.com/


Top
 Profile E-mail  
    
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group