Error incrementing integer value

I have an array of objects, where the object has a private variable defined in the header file as

int _no_of_points;

In the constructor i initialise it:

_no_of_points = 0;

But then in a later function where I say

_no_of_points++;

I get an error saying

Access violation reading location xxxxxxx

What on earth am I doing wrong?  I can post more code if necessary, but I would prefer it if someone could just say "you're probably locking the memory somewhere else with code like xxxxxxxx, try looking for yyyyyyyyyy" :-)

Cheers,

FatBoyTim
FatBoyTimAsked:
Who is Participating?
 
rcarlanCommented:
I'd say you're calling the method that increments _no_of_points with a NULL instance pointer. Stop in debug and look at this.

Radu
0
 
AxterCommented:
Hi FatBoyTim,
>> int _no_of_points;
It should not be declared like that in the header file.
It should be declared extern in the header file, and in one of your *.cpp files it should be declared without the extern.

David Maisonave :-)
Cheers!
0
 
AxterCommented:
Disregard previous post.
I didn't realize that it was been declared inside a class.
0
 
AxterCommented:
Please post your code.

FYI:
You shouldn't start your variable names with an underscore.
Names that start with an underscore are reserved for the implementation IAW C++ standard.
0
 
FatBoyTimAuthor Commented:
Bang on Radu, thank you - I was accessing array element -14.  God, how stupid!  It's so obvious when you know the answer :-)

Thanks for your help guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.