schultz
July 29th, 2007, 08:18 PM
I just had a C++ doubt and found nowhere else to post. It is about the STL vector.
It is know this code is correct:
int buff[100];
vector<int> A(10, 18 ) ;
vector<int> B(buff, buff+100);
This should leave A with 10 copies of 18 and B with the contents of buff.
The problem is, analysing the code of the vector data structure, I find something like:
vector(size_t, const _Tp&);
...
template<typename _InputIterator> vector(_InputIterator, _InputIterator);
This, of course, if you ignore allocator issues. My doubt is why this code is not ambiguous, since if I call vector(10, 18 ), it fits in both prototypes? This is, since if _InputIterator = int and _Tp = int we should have two prototypes fitting vector(int, int), there should be an ambiguity.
Can some C++ guru help me with this?
It is know this code is correct:
int buff[100];
vector<int> A(10, 18 ) ;
vector<int> B(buff, buff+100);
This should leave A with 10 copies of 18 and B with the contents of buff.
The problem is, analysing the code of the vector data structure, I find something like:
vector(size_t, const _Tp&);
...
template<typename _InputIterator> vector(_InputIterator, _InputIterator);
This, of course, if you ignore allocator issues. My doubt is why this code is not ambiguous, since if I call vector(10, 18 ), it fits in both prototypes? This is, since if _InputIterator = int and _Tp = int we should have two prototypes fitting vector(int, int), there should be an ambiguity.
Can some C++ guru help me with this?