3

I have a vector of pairs

std::vector<int,double> lambda;

I would like to remove the kth element, i.e

lambda.erase(&lambda[k]);
lambda.erase(lambda[k]);

Both of these attempts throws a no matching function call error:

error: no matching function for call to β€˜std::vector<std::pair<int, double> >::erase(__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, double> >, std::pair<int, double> >::value_type&)’
    lambda.erase(lambda[k]);
songyuanyao
  • 169,198
  • 16
  • 310
  • 405

1 Answers1

1

std::vector::erase expects iterator as its argument; not the element itself or pointer to element.

You could

lambda.erase(lambda.begin() + k);
songyuanyao
  • 169,198
  • 16
  • 310
  • 405
  • I did not realise that it was exactly the same as that in the case where we have only one template parameter instead of a pair of template parameters. I was under the (false) impression that & was somehow overloaded and would return an iterator instead of a pointer. Thanks for the answer. –  Jul 03 '18 at 15:29