LearnFrenzy
Sign in Take a free test

Functions and Default Arguments · Functions MCQ · Question 19

What can std::function<int(int)> hold? Answer, explanation & discussion

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

What can a std::function<int(int)> object store?

  • A Only plain functions
  • B Any callable taking an int and returning something convertible to int: functions, lambdas (with captures), function objects Correct
  • C Only lambdas without captures
  • D Only member functions
Correct Answer: Option B

It uses type erasure, so different callable types share one variable type – handy for callbacks stored in containers.

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