sam
sam

Reputation: 1

auto is not allowed here in C++11

void OrderBook::withdrawOrder( string& time){

  orders.erase(std::remove(orders.begin(), orders.end(),[&time](auto 
  order){ return order.timestamp == time && order.username == "simuser"; }),
  orders.end());
    
  
}

This is my code, auto before criteria is giving error "auto is now allowed here". What am I doing wrong.```

Upvotes: 0

Views: 657

Answers (1)

eerorika
eerorika

Reputation: 238311

What am I doing wrong.

You are using auto for a lambda parameter in a language version where that's not allowed.

How do i fix it?

Potential solutions:

  • Upgrade your language standard to at least C++14, which is the language version where auto lambda parameters were introduced.
  • Use an explicitly typed parameter, if only one argument type is needed.
  • Use a named function class with a templated or overloaded function call operator instead of a lambda, if more than one argument type are needed.

Upvotes: 1

Related Questions