0

How check behaves as a function in this Code?

int countV(string_view word) {
     /*
       Lines of codes
     */
    auto check = [&](string_view s) {
    };
    for (int i = 0; i < n; ++i)
      for (int l = 5; i + l <= n; ++l)
        if (check(word)) ;
   
  }
SiIconic
  • 41
  • 3
  • you don't want to write out the type of a lambda, hence why the author of this code uses `auto` to let the compiler deduce it. – Raildex Nov 12 '21 at 12:06
  • 1
    @Raildex Actually, I want to. I just can't. ;-) – Deduplicator Nov 12 '21 at 12:07
  • 5
    the code should cause an error, because `check` does not return anything and `if (check(workd))` would fail – 463035818_is_not_an_ai Nov 12 '21 at 12:07
  • The type of `check` is a unique unnamed non-union non-aggregate class type, with an `operator()` member. See [lambda](https://en.cppreference.com/w/cpp/language/lambda) – Caleth Nov 12 '21 at 12:17
  • The `countV` function itself has a major problem since it doesn't `return` an `int` as promised and where does it get `n` from? Is it global or is `countV` a member function and `n` a member variable? – Ted Lyngmo Nov 12 '21 at 12:23

0 Answers0