FatBoyTim
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Disregard previous post.
I didn't realize that it was been declared inside a class.
I didn't realize that it was been declared inside a class.
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.
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.
ASKER
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
Thanks for your help guys
>> 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!