brackets

S

Stefan Ram

I am most probably not the first one who observes that this
now is a valid C++ program:

int main (){[]{}();}

. Or is it the first time you see this?
 
S

Seungbeom Kim

Stefan Ram said:
now is a valid C++ program:

int main (){[]{}();}

Are you sure? The lambda is lacking the function parameter parentheses.
I think you mean:

int main (){[](){}();}

Or it could have been:

int main (){[](){};}
 
S

Seungbeom Kim

Stefan Ram said:
now is a valid C++ program:

int main (){[]{}();}

Are you sure? The lambda is lacking the function parameter parentheses.
I think you mean:

int main (){[](){}();}

Actually, it turns out that the whole lambda-declarator, including
the parameter-declaration-clause in parentheses, is optional.
Therefore, []{} is a valid lambda expression.
 
S

Seungbeom Kim

int main (){[]{}();}

what does it mean?

[]{} is a "lambda expression" that denotes an anonymous function
that does nothing (like 'f' as with 'void f(){}').
[]{}() is a function call expression that calls the function (like 'f()').
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top