Do we have closures in C++?

前端 未结 6 597
慢半拍i
慢半拍i 2020-12-13 02:19

I was reading about closures on the net. I was wondering if C++ has a built-in facility for closures or if there is any way we can implement closures in C++?

6条回答
  •  情书的邮戳
    2020-12-13 03:00

    I suspect that it depends on what you mean by closure. The meaning I've always used implies garbage collection of some sort (although I think it could be implemented using reference counting); unlike lambdas in other languages, which capture references and keep the referenced object alive, C++ lambdas either capture a value, or the object refered to is not kept alive (and the reference can easily dangle).

提交回复
热议问题