If lambdas are classes, should you be able to use inheritance? #1951
Replies: 2 comments 8 replies
-
I'm pulling together the initial lambdas proposal, so would be great to understand this use-case. I'm trying to think through what this looks likes, on the assumption that in "C++ lambdas are regular classes with some syntax sugar" follows through to Carbon. What we're saying in this case is that lambdas could inherit from a base class, while implementing some "
I think the thing from my perspective is: What does allowing lambdas having a base class allow a programmer to accomplish, and how do other languages which allow this construct cope with namespace clashes in captures? |
Beta Was this translation helpful? Give feedback.
-
I don't think this particular use case requires inheritance at all -- you can just write it as a function:
If you have a more complicated situation where you really do need inheritance, I think my preference would be to write that as an actual class with a custom |
Beta Was this translation helpful? Give feedback.
-
C++ lambdas are regular classes with some syntax sugar, so why are lambdas so much more limited than classes?
For instance, if you have a Transaction class, why not allow a lambda to be a subclass of Transaction?
Note that this isn't all that unusual or unreasonable. As an example, in the programming language BETA (successor to Simula) you can do this:
And use inheritance like this:
Beta Was this translation helpful? Give feedback.
All reactions