私は非常に奇妙な問題を抱えています
このようなコードの場合
template <typename T>
struct A{
explicit A(unsigned int size = 0, const T &t = T())
{
}
template <typename InputIterator>
A(InputIterator first, InputIterator last) {
for(;first != last ; ++first)
{
*first; //do something with iterator
}
}
};
たとえば、定義するとき
A<int> a(10,10);
最初のコンストラクターの代わりに、イテレーターの 2 番目のコンストラクターが使用されます。同じように見えるとき、ベクトルコンストラクターはどのように機能しますか?
explicit vector (size_type n, const value_type& val = value_type(),
const allocator_type& alloc = allocator_type());
template <class InputIterator>
vector (InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type());
そして、問題なくベクトル v(10,10) を作成できます。
PSこのようなエラーが発生しました
temp.cpp: In instantiation of ‘A<T>::A(InputIterator, InputIterator) [with = int; T = int]’:
temp.cpp:17:15: required from here
temp.cpp:12:4: error: invalid type argument of unary ‘*’ (have ‘int’)