double U[3];
int k;
for (k = 0; k < 3; k++) {
U[k] = expression4;}
for (int i = 0; i < 3; i++) {
d[0] = X21+U[i];
d[1] = Y21+U[i];
d[2] = Z21+U[i];
}
....}
This is not working for me as expected. When i debug it I see that the problem is that when i go from the setmethod to the updatemethod the values of X,Y,Z are lost and it gives some very big numbers to them instead of the previously calculated ones. I should note that all of the variables X,Y,Z,U,d are also defined in the header file but none of them is included in any of the variables that are used in the constructor. Can you think anything that I am not aware of? In another class that I have with the same methods that have the same parent class with this one, I have a similar code there that works fine.
Thank you for your help!!
p.s. sorry if it is something easy for you but you can forgive me as I have a structural engineering background and not computer science. :D
When i debug it I see that the problem is that when i go from the setmethod to the updatemethod the values of X,Y,Z are lost and it gives some very big numbers to them instead of the previously calculated ones
This is because you made 2 sets of variables:
- One that's part of your class (defined in your header). This is the one you want to change
- One that's locally defined in setMethod. This is the one you're ACTUALLY changing.
This line here is the culprit:
1 2 3 4
Classname::setMethod(anotherclass *anotherclass)
{//....
//double X,Y,Z; // <- get rid of this
X=0;
By putting that line in, you're recreating another set of variables with the same names, which you don't want to do.
You might also have a similar problem in updateMethod, but I can't tell from this code.