I have several different objects, each with a common base class. Id like to create a base-class reference to the i-th object. Is there a better way than:
1 2 3 4 5
Base& base = (i == 0) ? Obj0 :
(i == 1) ? Obj1 :
(i == 2) ? Obj2 :
...
(i == 7) ? Obj7;
If you absolutely cannot use an array (and if you cannot, I suggest you go back and look at your design again), then use a pointer instead of the reference.
I can't use an array as each object is a different class, though all inherited from the same base. But maybe I can use a tuple? I'll give this a try. The other option I found was, as you suggested, using base pointers with if's, then creating the reference from *pointer. I was just looking for something more streamlined/clever. Thanks all for your help!