LearnFrenzy
Sign in Take a free test

Lambda Expressions · Lambda MCQ · Question 13

When to use std::function Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

When is std::function<void(int)> the right choice?

  • A Always, instead of auto
  • B When you need to store callables of different types behind one signature, e.g. a vector of callbacks Correct
  • C For the fastest calls
  • D To make lambdas recursive in C++23
Correct Answer: Option B

It erases the type at a small run-time cost; auto and templates keep the exact type.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links