S
subramanian100in
I am copying the following text as it is from Stroustrup's TC++PL 3rd
edition, page 450.
It says:
"Note that a constructor given two arguments of the same type can be a
match for more than one constructor. For example,
vector<int> v(10, 50); // (size, value) or (iterator1, iterator2)?
The problem is that the declaration
template <class In> vector<In first, In last, const A& = A());
doesn't actually say that 'In' must be an input iterator. The
declaration specifies only that the constructor's two first arguments
must be of the same type. The unfortunate consequence is that v's
declaration causes compile-time or link-time errors."
My Doubt:
---------------
I ran the following program with v(10, 50). It didn't give any
compilation or linker error. Instead it printed ten 50s. I am using g+
+ 3.4.3
Is it wrong with the compiler or my understanding that 'In' should be
an input iterator is wrong. ? Kindly clarify.
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v(10, 50);
for (vector<int>::const_iterator cit = v.begin(); cit !=
v.end(); ++cit)
cout << *cit << endl;
return EXIT_SUCCESS;
}
Thanks
V.Subramanian
edition, page 450.
It says:
"Note that a constructor given two arguments of the same type can be a
match for more than one constructor. For example,
vector<int> v(10, 50); // (size, value) or (iterator1, iterator2)?
The problem is that the declaration
template <class In> vector<In first, In last, const A& = A());
doesn't actually say that 'In' must be an input iterator. The
declaration specifies only that the constructor's two first arguments
must be of the same type. The unfortunate consequence is that v's
declaration causes compile-time or link-time errors."
My Doubt:
---------------
I ran the following program with v(10, 50). It didn't give any
compilation or linker error. Instead it printed ten 50s. I am using g+
+ 3.4.3
Is it wrong with the compiler or my understanding that 'In' should be
an input iterator is wrong. ? Kindly clarify.
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v(10, 50);
for (vector<int>::const_iterator cit = v.begin(); cit !=
v.end(); ++cit)
cout << *cit << endl;
return EXIT_SUCCESS;
}
Thanks
V.Subramanian