0

Hello, I am working on a program for school and this is my first experience with arrays of objects. I am passing the array of objects into a function, and from within that function I am running another function that takes an individual object from the array as an arguemnt and then modifies some of its variables (the variables are public). It takes all of the arguemnts fine and no errors come up, however when I access the variables from within my main, they are not the modified versions that they are when accessed in my function. So overall my question is whether or not arrays of objects are passed by reference by default as most arrays are? Or if there is something I must do in order to solve my problem described above (note: I would like to avoid using global variables if possible)? Thanks and I can provide the relevant code if it is necessary.

~~Tofugames

EDIT: Well it turns out I just made a really dumb mistake and forgot to make one of the function arguments for the individual object a reference, and now everything is working fine! Also, how do I set the status of my topic to solved?

Edited by tofugames: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by thekashyap
0

Arrays are passed by reference.
Your problem should be with the second function (not passing the single object by ref/ptr).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.