Error in my app

Started by
8 comments, last by logout 20 years, 11 months ago

  

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
Advertisement
quote:Original post by logout
So can anyone spot the problem ?

What is the problem?
sorry.. i did forget that

it crashes .. thats the error
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]
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
_________________________________________"You're just jelous because the voices only talk to me"
When you run it in the debugger, what line does it crash on?

How appropriate. You fight like a cow.
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]
Whoa, it crashes when you push a pointer into a vector? That''s very bizarre.
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.
how can i ensure that i got a legal this if CKeeper is a singleton ?

[edited by - LogouT on May 1, 2003 5:51:55 PM]

This topic is closed to new replies.

Advertisement