My title doesn't do a good job of explaining what I'm trying to do, which has likely hindered my ability to find a solution by searching.
I have a group of object instances, which are also in an array. I wish to access these instances by reference both while iterating through the array and individually.
This code is a simplified version of my problem:
This is my first time working in C++ and I'm clearly struggling with the syntax. My use of structs was an attempt to simplify my example; my code uses classes form a library I'm writing.
Your example gave me the building blocks to achieve what I'm really trying to do, which is more accurately represented by the following example:
This is my first time working in C++ and I'm clearly struggling with the syntax. My use of structs was an attempt to simplify my example
You may be surprised to know that in C++ the only difference between structs and classes is that in a class, anything is by default is declared as "private"- That's it!
References are good to know: However, I don't think that you are using them right. A reference is an automatic "call by reference", so that you don't have to have a list of pointers.
InvalidApple, your version appears cleaner, but it loses one of the original requirements; I need to address each instance by its own variable name, not just by its array index.