Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello again. I've managed to complete a program, and it compiles fine, but as soon as I try to run it it crashes. The debugger claims this is due to unhandled exception c0000005. The only article I can find on this talks about the dangers of using C functions like strlength, but I'm not using anything like that here.

I get a breakpoint at an enumeration when it fails

C++
enumerated card_status {tapped, untapped, damaged}

class C
{
public:

C()
{
status = tapped;
}

void change_status
{
if (status == tapped)
status = untapped;
};

private:
card_status status;
};

And it locks up at status = tapped; every time. Does anyone have any idea what the problem here is? Thanks for your time.
Posted
Updated 7-Aug-14 15:44pm
v2
Comments
chandanadhikari 8-Aug-14 1:59am    
hi,
what is 'enumerated' in the first line of code . Is it something you have defined because otherwise it should be 'enum' if you are declaring an enumeration.
An enum is declared as :
enum colors_t {black, blue, green};
You can check if changing it to enum helps.
CPallini 8-Aug-14 3:11am    
You should post the actual code. The 'enumerated' line is meaningless in C++.
Philippe Mori 8-Aug-14 20:57pm    
When the debugger stop on the exception, you normally have all necessary information to verify that your object is valid.

C0000005 indicates an access vialoation. Usually it means you are trying to access invalid memory, either by dereferencing a pointer not pointing to valid memory, or by using a pointer to reach past the bounds of the memory it points to.

In your case, it looks like you're somehow invoking the constructor C::C() in an inappropriate way, i. e. on an invalid memory address. This is only possible if you directly call the constructor on an invalidated object, or on a pointer that was never instantiated with an object. The bug is in the code that calls the constructor!

P.S.:
Here are a few examples that may cause error C0000005:

1. wrong way to construct an object
C++
void construct_fail()
{
   C* pc;   // dangerous: declare pointer without initialization!
   pc->C(); // error C0000005
}

2. trying to "reinitialize" a destroyed object
C++
void reinitialize_fail(C* pc)
{
   // dangerous: state of pc is unknown at this point - it may be valid or invalid
   pc->C(); // error: if pc is invalid, you get error C0000005, otherwise you construct 
            // an already constructed object, invoking another run-time error
}

3. Trying to construct an object in-place on an invalid memory pointer
C++
C* make_C(void* my_memory_block)
{
   return new (my_memory_block) C; // calls constructor, but fails to check pointer validity
}
...
   void* memblock; // danger: unintialized pointer
   C* pc = make_C(mem); // error C0000005
 
Share this answer
 
v2
As Stefan said it will be an access vilation.

I guess you accessing a pointer "C*" but it NEEDS to point to a object:

C++
C *p = new C();
//do stuff with p
delete p;//free memory


You should provide the code if it stays unclear.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900