Access violation detection point 0x00000000. "new" keyword?

I have two classes: A and Bar, both have a common header file, which essentially has Foo * foo. Class A creates a Bar bar object. It works great. However, if I create an instance of the object

Bar* bar = new Bar(); 

I get an access violation when a bar tries to do something with foo. Why does it matter?

If I do not use "new", it works fine. This is mistake:

 Unhandled exception at 0x003c17ea in Direct3DTutorial7.exe: 0xC0000005: Access violation reading location 0x00000000. 

Thanks.

+6
source share
3 answers
 0xC0000005: Access violation reading location 0x00000000. 

This means that you are looking for a null pointer, probably in the Bar constructor or in some other code called by this constructor. Use the debugger to pinpoint exactly where.

+13
source

I would suggest that you do not highlight your Foo object. Since this is a global variable, it is initialized to zero when the program starts, which for pointers corresponds to a zero value.

0
source

Did you remember to create the Foo object and assign it to the foo pointer? It looks like your Bar constructor is trying to do something with foo, but you haven't created a Foo object yet.

0
source

Source: https://habr.com/ru/post/897893/


All Articles