Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

STL map+vector compilation failure issue

0 views
Skip to first unread message

bolta...@yahoo.co.uk

unread,
Apr 30, 2009, 9:02:30 AM4/30/09
to
Hi

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


Thomas J. Gritzan

unread,
Apr 30, 2009, 9:13:28 AM4/30/09
to
bolta...@yahoo.co.uk schrieb:

> Hi
>
> 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));

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

bolta...@yahoo.co.uk

unread,
Apr 30, 2009, 9:17:28 AM4/30/09
to
On Thu, 30 Apr 2009 15:13:28 +0200
"Thomas J. Gritzan" <phygon_...@gmx.de> wrote:
>
>
>bolta...@yahoo.co.uk schrieb:
>> Hi
>>
>> 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));
>
>Because there's no constructor in vector that takes a pair?

But why would it need a specific pair constructor anyway? Why doesn't it just
use the generic templated constructor?

B2003

red floyd

unread,
Apr 30, 2009, 9:45:30 AM4/30/09
to
bolta...@yahoo.co.uk wrote:
> Hi
>
> 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);
>

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.

Vaclav Haisman

unread,
Apr 30, 2009, 9:46:22 AM4/30/09
to
std::vector has several ctors but none that would take value of type T. See
e.g. <http://stdcxx.apache.org/doc/stdlibref/vector.html#idx1305>.

--
VH

Pete Becker

unread,
Apr 30, 2009, 10:01:12 AM4/30/09
to

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)

0 new messages