TRT
Sign in

Advanced · Module 10 · Lesson 5 of 6

Member Pointers and std::function Callables

Store data and method pointers as values, invoke them on chosen objects, and erase callable types behind a common wrapper.

Pro — members onlyAbout 10 minutes

By the end you can

  • Declare and invoke pointers to data members and member functions
  • Wrap lambdas and bound methods in a type-erased callable
  • Explain when member pointers beat virtual dispatch

Builds on Lambdas: Captures, mutable and Algorithms.

01 · A question first

A UI table lists ten counters and one display routine. A scheduler stores the routine once and applies it to each object in turn. How can a function and a field be stored like data and invoked later on any instance?

Make a guess before you read on.

02 · The idea

Members only

Unlock the full lesson

This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.

What's inside

  • Start with the problem
  • How the idea works
  • Why it is correct
  • What it costs
  • Type erasure overhead versus templates
  • A member pointer table with std::function example
  • Member pointers versus virtual calls
  • Pitfalls and variations

03 · Practice

Something wrong with this lesson? Report a problem