Portál AbcLinuxu, 14. května 2025 16:45
short int* p_sh = &*mujVector.begin()
.
&*mujVector.begin()
vráti pointer na prvý prvok. Len menšia oprava - *mujVector.begin()
nie je hodnota, ale referencia. Takže je možné napísať
*mujVector.begin() = 42;
int * p = mujVector.begin()
?
std::vector<int>::iterator it = mujVector.begin();Iterátor se chová stejně jako pointer.
Mylite se, u vektoru je vyslovne receno, ze polozky musi byt usporadany souvisle za sebou.
The elements of a vector are stored contiguously, meaning that if v is a vector<T, Allocator> where T is some type other than bool, then it obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size().
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.