dimanche 22 octobre 2017

c++ [] sintax in functions

I found this code:

string encrypt(string text, int rule) {
  std::for_each(text.begin(), text.end(), [&](char &c) {c += rule; });
  return text;
};

I know what it does, and I kind of understand how it works, but I would like to understand the function they are using as an argument, specifically the [&].

Aucun commentaire:

Enregistrer un commentaire