Hi people!
I'm starting programming in C++. I thought it would be easy because I have some experience with Java, but it is not so, really.
I'm completely confused about an increment of a variable in a function of one class of my program.
Here's the code:
This is the .hh file, where I declare the private variables:
1 2 3
|
long mostras;
double sumX;
double sumX2;
|
Here I declare a variable of type "long", which I want to increment everytime I call to a function in the class.
In the constructor of the class (.cc file) I say:
And then, in another funcion of the class (.cc file) I say:
1 2
|
mostras++; // Increment of the variable "mostras"
cout<<"samples computed: "<<mostras;
|
When I run the program:
samples constructor = 0
samples computed = 1056964609
I can't understand why it jumps from 0 to 10569646!!!
I incremented it only once and I am not modifying this variable in any other lines!!!
I'm sure this is an stupid thing, what I'm doing, but if anybody could help me...
thanks a lot.