• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ Question. Passing array of class objects to and back from a function

Jay59express

Senior member
Hello,
I have a class called ArrayNode, which is just a node in an array element (not important). In main I declare an array of ArrayNodes, like this:
ArrayNode a[126];
So I have 126 instances of ArrayNode, The question is, how can I pass this array of class instances to a function so the function has complete access to the array, including modifying it, and when the function ends, the original calling function has the updated version of the array.
Man I suck at explaining that, but I think you guys can figure it out 🙂

The function I am using is called Encode(a) if it helps.
Thanks!
 
All arrays are passed by reference, a class works exactly the same as an int, double. You must have a lousy textbook if it doesn't have examples of this.

mybar foo [ 100 ] ;
happyfunc( foo );


void happyfunc (mybar* foo)
{
foo[ 17 ] = 1; // if it was an int array

// class members
foo[ 17 ].how = 1;
foo[ 17 ].why = 2;
}
 
Try accepting a reference to an array. I believe the function would be Encode(ArrayNode(& a)[]);
If this doesn't work just accept a pointer: Encode(ArrayNode *a);
 
Back
Top