Archived

This topic is now archived and is closed to further replies.

logout

Error in my app

Recommended Posts


  

class CKeeper;
class CChild
{
	public:
		virtual void Execute(int icode){}
};
class CTestClass : public CChild
{
	public:
		virtual void Execute(int icode);
};

CKeeper
{
	public:
		void Attach(CChild *cc);

	private:
		vector<CChild*> vC;
};
  
Now the problem comes when i want to attach CTestClass into the CKeeper class
  
void CKeeper::Attach(CChild *cc)
{
	vC.push_back(cc);
}
  
Later in the code i call vC->Execute(some_var); So can anyone spot the problem ? btw this is a re type, cause my original code is too long and to unclear

Share this post


Link to post
Share on other sites
Your code looks fine. Crashes involving constructs like that are almost always caused by invalid pointers.

Have you created the class you're passing to Attach using new? If you just took the address of a static object, you may be calling Execute on something that has quietly gone out of scope and died!

Are you sure you never changed the pointer, (i.e. set it to NULL) before you passed it?

Are you sure you didn't delete the object before you passed it?

[edited by - micepick on April 29, 2003 8:29:06 PM]

Share this post


Link to post
Share on other sites
doesn''t the program have to have a ''main'' function? or is that just a piece of the program...?

_________________________________________
"Why, why why does everyone ask ''''why'''' when ''''how'''' is so much more fun"
-Spawn 1997

Share this post


Link to post
Share on other sites
well the code crash on the line:
vC.push_back(cc);


is there anyway i can get a more description of the error ?
using a debuger or something ?

edit:
I tryed using the debuger and got this error:

iside the vector header file

  
size_type size() const
{ // return length of sequence

return (_Myfirst == 0 ? 0 : _Mylast - _Myfirst); // the error is on this line

}



I also got this:
Unhandled exception at 0x0041a8b6 in GfxEngine.exe: 0xC0000005: Access violation reading location 0x00000004.

[edited by - LogouT on April 29, 2003 8:42:31 PM]

Share this post


Link to post
Share on other sites
It''s not bizarre at all, if vC is not valid, which happens if ''this'' is not valid, which happens if you call Attach() on a CKeeper pointer that is NULL. Which, dollars to donuts, is what you are doing. Go down in the traceback and find out what is calling Attach on a pointer that is set to NULL, and fix it.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites