mardi 1 décembre 2015

recursive lambda and capture (segfault)

Compiler

g++ (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010

Snippet 1 (& capture)

#include <functional>

int main()
{
  std::function<void ()> func = [&] () {
    func();
  };
  return 0;
}

Snippet 2 (func capture)

#include <functional>

int main()
{
  std::function<void ()> func = [func] () {
    func();
  };
  return 0;
}

Both snippets compile but why does running the second result in a segmentation fault?

Aucun commentaire:

Enregistrer un commentaire