STL map+vector compilation failure issue

B

boltar2003

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
 
T

Thomas J. Gritzan

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.
 
B

boltar2003

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
 
V

Vaclav Haisman

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?
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>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top