Associate
I have a class which has a vector list of the same type of class, I also have a method that calls a function and recalls it for each in the vector.
(I have changed some method and variable names as I can't post my actual code)
The class which is called has a integer variable in the header file and a method which increments the integer.
"an" is set in the constructor to 0. You would expect the first time add() is called that all instances of "an" would be 1, then 2 etc. However, only the 1st instance is 1, then 2, the rest do not retain the value.
If I cout in another method I get
I have no idea what is causing this to happen, it just doesn't make any sense.
Code:
void Body::add()
{
obj.doSomething();
for each(Body bo in sat)
{
bo.add();
}
}
(I have changed some method and variable names as I can't post my actual code)
The class which is called has a integer variable in the header file and a method which increments the integer.
Code:
private:
int an;
Code:
void here::doSomething()
{
an++;
}
"an" is set in the constructor to 0. You would expect the first time add() is called that all instances of "an" would be 1, then 2 etc. However, only the 1st instance is 1, then 2, the rest do not retain the value.
If I cout in another method I get
Code:
1
0
0
0
2
0
0
0
3
0
0
0
etc..
I have no idea what is causing this to happen, it just doesn't make any sense.
Last edited: