Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

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
0
FatBoyTim
Asked:
FatBoyTim
  • 3
1 Solution
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now