How can I store objects in arrays?


#1

I have multiple objects, named M1, M2, M3…, that have been injected into a chaiscript. I’d like to store them in an array so that I can refer to them using an index. However, when I tried to write

meters = [M1, M2, M3];

I got errors about no clone or copy constructors being available. But I don’t want copies, I really just want the references. I tried

meters = [&M1, &M2, &M3]

but the compiler didn’t like that either.

Any way to do this?

Thanks


#2

You’ll want to do something like:

var meters=[]
meters.push_back_ref(M1)
meters.push_back_ref(M2)
meters.push_back_ref(M3)

To explicitly not make a clone when adding the object to the vector.


#3

Thank you - that worked perfectly