teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コンパイル結果を情報として追記

2018/08/06 01:17

投稿

luma
luma

スコア183

title CHANGED
File without changes
body CHANGED
@@ -31,6 +31,7 @@
31
31
  これはコンパイルできますが,似たような設計にしようとして,
32
32
 
33
33
  ```cpp
34
+ /** a.cpp **/
34
35
  #include<vector>
35
36
  using namespace std;
36
37
 
@@ -48,17 +49,44 @@
48
49
  int main() {
49
50
  vector<int> a(2, 3);
50
51
  vector<int> b(begin(a), end(a));
51
- X<int> x(2, 3); // compile error (この行ではなくdistanceでerror)
52
+ X<int> x(2, 3); // compile error ~~(この行ではなくdistanceでerror)~~ すみませんここも compile errorでした
52
53
  X<int> y(begin(a), end(a)); // ok
53
54
  return 0;
54
55
  }
55
56
  ```
56
57
 
57
- とするとdistanceのところでdistance(int&, int&)がないといわれます.
58
+ とするとdistanceのところでdistance(int&, int&)がないといわれます.(追記参照)
59
+
58
60
  `explicit`をつけたりもしましたが変わりませんでした.
59
61
 
60
62
  どうすればvectorのコンストラクタのような振る舞いになるでしょうか.
61
63
 
62
64
  g++のversionは`7.3.0`でした.
63
65
 
64
- よろしくお願いします.
66
+ よろしくお願いします.
67
+
68
+ 追記:
69
+
70
+ 上記をコンパイルした結果です.
71
+
72
+ ```
73
+ $ g++ a.cpp
74
+ a.cpp: In instantiation of ‘X<T>::X(InputIter, InputIter) [with InputIter = int; T = int]’:
75
+ a.cpp:18:16: required from here
76
+ a.cpp:11:44: error: no matching function for call to ‘distance(int&, int&)’
77
+ X(InputIter fi, InputIter la): n(distance(fi, la)) {
78
+ ~~~~~~~~^~~~~~~~
79
+ In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
80
+ from /usr/include/c++/7/vector:60,
81
+ from a.cpp:1:
82
+ /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)
83
+ distance(_InputIterator __first, _InputIterator __last)
84
+ ^~~~~~~~
85
+ /usr/include/c++/7/bits/stl_iterator_base_funcs.h:138:5: note: template argument deduction/substitution failed:
86
+ /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]’:
87
+ a.cpp:11:44: required from ‘X<T>::X(InputIter, InputIter) [with InputIter = int; T = int]’
88
+ a.cpp:18:16: required from here
89
+ /usr/include/c++/7/bits/stl_iterator_base_funcs.h:138:5: error: no type named ‘difference_type’ in ‘struct std::iterator_traits<int>’
90
+ ```
91
+
92
+ `(この行ではなくdistanceでerror)`と書いていた行もエラーでしたすみません…