Код: Выделить всё
int main() {
auto fn = [](this auto&& self, T n) {
if (n > 0) {
self(n - 1);
}
};
fn(3);
}
Код: Выделить всё
:4:13: error: function 'operator()' with deduced return type cannot be used before it is defined
4 | self(n - 1);
| ^
:8:7: note: in instantiation of function template specialization 'main()::(anonymous class)::operator()' requested here
8 | fn(3);
| ^
:2:15: note: 'operator()' declared here
2 | auto fn = [](this auto&& self, T n) {
| ^
1 error generated.
Compiler returned: 1
Почему рекурсивный лямбда с параметрами шаблона и аргументом Decucing (this) не работает?>
Подробнее здесь: https://stackoverflow.com/questions/796 ... e-not-work