回答編集履歴
4
begin()での方法追記
answer
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
> .begin()ではエラーになります
|
8
8
|
|
9
9
|
[std::vector::begin](https://cpprefjp.github.io/reference/vector/vector/begin.html)が返すのは先頭要素のポインタではなくイテレータです。
|
10
|
+
`begin()`でやりたいなら、`&*v.begin()`。
|
11
|
+
`*`をつけて先頭要素の参照を取得し、さらに`&`をつけてアドレスを取得。
|
10
12
|
|
11
13
|
---
|
12
14
|
|
3
front(),data()追記
answer
CHANGED
@@ -6,4 +6,8 @@
|
|
6
6
|
|
7
7
|
> .begin()ではエラーになります
|
8
8
|
|
9
|
-
[std::vector::begin](https://cpprefjp.github.io/reference/vector/vector/begin.html)が返すのは先頭要素のポインタではなくイテレータです。
|
9
|
+
[std::vector::begin](https://cpprefjp.github.io/reference/vector/vector/begin.html)が返すのは先頭要素のポインタではなくイテレータです。
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
[`&v.front()`](https://cpprefjp.github.io/reference/vector/vector/front.html)や[`v.data()`](https://cpprefjp.github.io/reference/vector/vector/data.html)でもよいです。
|
2
beginについて追記
answer
CHANGED
@@ -1,3 +1,9 @@
|
|
1
1
|
`vector<VERTEX3D> v;`が空でないのなら`&v[0]`でよいです。
|
2
2
|
|
3
|
-
[std::vector::operator[]](https://cpprefjp.github.io/reference/vector/vector/op_at.html)は要素への参照を返します。[vectorの要素はメモリ上で連続していることが保証されている](https://cpprefjp.github.io/reference/vector/vector.html)ため、`&v[0]`で取得した先頭要素のアドレスから要素数分連続して格納されています。
|
3
|
+
[std::vector::operator[]](https://cpprefjp.github.io/reference/vector/vector/op_at.html)は要素への参照を返します。[vectorの要素はメモリ上で連続していることが保証されている](https://cpprefjp.github.io/reference/vector/vector.html)ため、`&v[0]`で取得した先頭要素のアドレスから要素数分連続して格納されています。
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
> .begin()ではエラーになります
|
8
|
+
|
9
|
+
[std::vector::begin](https://cpprefjp.github.io/reference/vector/vector/begin.html)が返すのは先頭要素のポインタではなくイテレータです。
|
1
メモリ上で連続している旨追記
answer
CHANGED
@@ -1,1 +1,3 @@
|
|
1
|
-
`vector<VERTEX3D> v;`が空でないのなら`&v[0]`でよいです。
|
1
|
+
`vector<VERTEX3D> v;`が空でないのなら`&v[0]`でよいです。
|
2
|
+
|
3
|
+
[std::vector::operator[]](https://cpprefjp.github.io/reference/vector/vector/op_at.html)は要素への参照を返します。[vectorの要素はメモリ上で連続していることが保証されている](https://cpprefjp.github.io/reference/vector/vector.html)ため、`&v[0]`で取得した先頭要素のアドレスから要素数分連続して格納されています。
|