简体   繁体   中英

Default value of function as a function argument

How do I properly define a default return value of a function that is an argument of another function?

Let's say I have a function like this:

bool x( ... , std::function<bool( ... )> func ) { ... ; return func( ... ); }

I would like x to return true if it's called without the last argument.

您可以将lambda指定为func的默认值,例如

bool x( ... , std::function<bool( ... )> func = []( ... ) { return true; } ) { ... ; return func( ... ); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM