I'm probably making some idiot mistake but can someone tell me why the
following fails to compile with a no matching function call error under
gcc:
map<int,vector<pair<int,int> > > m;
m[123] = vector<pair<int,int> >(pair<int,int>(2,3));
However a simple integer vector in the map compiles just fine:
map<int,vector<int> > m2;
m2[123] = vector<int>(2);
I can easily work around the issue but I'd like to know what I'm doing
wrong anyway. Thanks for any help
B2003
Because there's no constructor in vector that takes a pair?
Try this:
m[123] = vector<pair<int,int> >( 42, make_pair(2,3) );
This constructs a vector with 42 elements, each copy constructed from a
pair<int,int>.
The make_pair function allows to omit the template parameters of the pair.
--
Thomas
But why would it need a specific pair constructor anyway? Why doesn't it just
use the generic templated constructor?
B2003
Because the int parameter to the vector constructor is not a member, but
a *COUNT*.
m2[123] = vector<int>(2);
Creates a vector with 2 default constructed ints.
Try reading the documentation on vector.
--
VH
Which generic templated constructor do you want it to use? Hint: don't
guess; look at the specification for vector.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)