Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access violation reading location 0x00000000. 'new' keyword?

Tags:

c++

I have two classes, A and Bar, both share a header file that has essentially Foo* foo in it. Class A instantiates an object Bar* bar. This works fine. However, if I make the instantiation of the object

Bar* bar = new Bar();

I get an access violation when bar attempts to do something with foo. Why does this make a difference?

If I don't use 'new' it works fine. This is the error:

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

Thanks.

like image 385
Dollarslice Avatar asked Sep 23 '11 13:09

Dollarslice


1 Answers

0xC0000005: Access violation reading location 0x00000000.

This means you're dereferencing a null pointer, likely in the constructor of Bar, or in some other code called by this constructor. Use a debugger to determine exactly where.

like image 147
hammar Avatar answered Sep 28 '22 08:09

hammar