This is a really basic question, but I'm not sure how to google it.
I have a pointer to a vector (or array of pointers), say
vector<int *> *p;
Is there an alternative syntax for indexing this array, other than
(*p)[i];
akin to the -> operator?
p->at(i) is similar but does bounds checking and throws an exception if i is out of range. Looks nicer than both your and Luchian's solutions (IMO), and is a little safer.
Yes -
p->operator[](i);
but it's not really better if you ask me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With