質問編集履歴
1
コンパイル結果を情報として追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,6 +64,8 @@
|
|
64
64
|
|
65
65
|
```cpp
|
66
66
|
|
67
|
+
/** a.cpp **/
|
68
|
+
|
67
69
|
#include<vector>
|
68
70
|
|
69
71
|
using namespace std;
|
@@ -98,7 +100,7 @@
|
|
98
100
|
|
99
101
|
vector<int> b(begin(a), end(a));
|
100
102
|
|
101
|
-
X<int> x(2, 3); // compile error (この行ではなくdistanceでerror)
|
103
|
+
X<int> x(2, 3); // compile error ~~(この行ではなくdistanceでerror)~~ すみませんここも compile errorでした
|
102
104
|
|
103
105
|
X<int> y(begin(a), end(a)); // ok
|
104
106
|
|
@@ -110,7 +112,9 @@
|
|
110
112
|
|
111
113
|
|
112
114
|
|
113
|
-
とするとdistanceのところでdistance(int&, int&)がないといわれます.
|
115
|
+
とするとdistanceのところでdistance(int&, int&)がないといわれます.(追記参照)
|
116
|
+
|
117
|
+
|
114
118
|
|
115
119
|
`explicit`をつけたりもしましたが変わりませんでした.
|
116
120
|
|
@@ -125,3 +129,55 @@
|
|
125
129
|
|
126
130
|
|
127
131
|
よろしくお願いします.
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
追記:
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
上記をコンパイルした結果です.
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
$ g++ a.cpp
|
146
|
+
|
147
|
+
a.cpp: In instantiation of ‘X<T>::X(InputIter, InputIter) [with InputIter = int; T = int]’:
|
148
|
+
|
149
|
+
a.cpp:18:16: required from here
|
150
|
+
|
151
|
+
a.cpp:11:44: error: no matching function for call to ‘distance(int&, int&)’
|
152
|
+
|
153
|
+
X(InputIter fi, InputIter la): n(distance(fi, la)) {
|
154
|
+
|
155
|
+
~~~~~~~~^~~~~~~~
|
156
|
+
|
157
|
+
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
|
158
|
+
|
159
|
+
from /usr/include/c++/7/vector:60,
|
160
|
+
|
161
|
+
from a.cpp:1:
|
162
|
+
|
163
|
+
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:138:5: note: candidate: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator)
|
164
|
+
|
165
|
+
distance(_InputIterator __first, _InputIterator __last)
|
166
|
+
|
167
|
+
^~~~~~~~
|
168
|
+
|
169
|
+
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:138:5: note: template argument deduction/substitution failed:
|
170
|
+
|
171
|
+
/usr/include/c++/7/bits/stl_iterator_base_funcs.h: In substitution of ‘template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) [with _InputIterator = int]’:
|
172
|
+
|
173
|
+
a.cpp:11:44: required from ‘X<T>::X(InputIter, InputIter) [with InputIter = int; T = int]’
|
174
|
+
|
175
|
+
a.cpp:18:16: required from here
|
176
|
+
|
177
|
+
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:138:5: error: no type named ‘difference_type’ in ‘struct std::iterator_traits<int>’
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
`(この行ではなくdistanceでerror)`と書いていた行もエラーでしたすみません…
|