E
Equus
Hi all,
I have a question concerning an index that I'm creating on a vector of
objects such that I can refer to the objects by integer. The index
will change, the vector *will not* (obviously, otherwise the pointers
would screw up). I have:
vector<MyObject> myVector;
map<size_t, MyObject&> myIndex;
Now, the compiler chucks at the declaration of myIndex giving "error:
reference to reference is not allowed". This is presumably because of
the reference to type MyObject in the map declaration. So, my
question is: is this a valid use of references in C++? Should I just
be using a plain old pointer to point to the various MyObjects in
myVector?
Thanks,
Chris
I have a question concerning an index that I'm creating on a vector of
objects such that I can refer to the objects by integer. The index
will change, the vector *will not* (obviously, otherwise the pointers
would screw up). I have:
vector<MyObject> myVector;
map<size_t, MyObject&> myIndex;
Now, the compiler chucks at the declaration of myIndex giving "error:
reference to reference is not allowed". This is presumably because of
the reference to type MyObject in the map declaration. So, my
question is: is this a valid use of references in C++? Should I just
be using a plain old pointer to point to the various MyObjects in
myVector?
Thanks,
Chris