回答編集履歴
1
追記
answer
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
> **引数としているvector**のところで以下のようなエラーが出ています。
|
2
2
|
> void max(int* v) { ... }
|
3
3
|
|
4
|
-
もしかして: int* と vector<int> は同じものと思っていますか?
|
4
|
+
もしかして: int* と vector<int> は同じものと思っていますか?
|
5
|
+
|
6
|
+
```C++
|
7
|
+
void max(const std::vector<int>& v) {
|
8
|
+
|
9
|
+
std::vector<int>::const_iterator itr_max = std::max_element(v.begin(), v.end());
|
10
|
+
size_t max_index = std::distance(v.begin(), itr_max);
|
11
|
+
|
12
|
+
std::cout << "max element id=" << max_index << endl;
|
13
|
+
std::cout << "max element (hairetsu):" << v[max_index] << std::endl;
|
14
|
+
std::cout << "max element (pointer):" << *itr_max << std::endl;
|
15
|
+
}
|
16
|
+
```
|