Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:49:50+00:00 2026-06-11T21:49:50+00:00

Member functions have an implicit this pointer parameter. Why does std::function accept this signature,

  • 0

Member functions have an implicit this pointer parameter. Why does std::function accept this signature, then, where S is a simple class? (complete sample)

std::function<void(S &)> func = &S::foo;

Calling it works, too, and distinguishes objects:

S s1 = {5};
S s2 = {6};

func(s1); //prints 5
func(s2); //prints 6

What I’d normally expect is that it needs a pointer, which works as well: (complete sample)

std::function<void(S * const)> func = &S::foo;

S s1 = {5};
S s2 = {6};

func(&s1); //prints 5
func(&s2); //prints 6

Why does the first one work when I pass a reference into the member function when the implicit this parameter is a pointer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:49:51+00:00Added an answer on June 11, 2026 at 9:49 pm

    std::function<SIG> can be constructed from many things that behave like functions, converting them to an appropriate std::function object.

    In this case void S::foo() behaves much like a function void foo_x(S&) (as in they both require an S to call, and potentially modify S, returning nothing). Consequently std::function<void(S&)> provides a constructor for converting the member function into a function object. I.e.

    std::function<void(S &)> func = &S::foo;
    

    uses a constructor, something like std::function<void(S&)>( void(S::)() ), to create something equivalent to:

    void foo_x(S & s ) { return s.foo(); }
    std::function<void(S&)> func = foo_x;
    

    Similarly,

    std::function<void(S * const)> func = &S::foo;
    

    is equivalent to

    void foo_x(S * const s ) { return s->foo(); }
    std::function<void(S* const )> func = foo_x;
    

    through a constructor like std::function<void(S* const )>( void(S::)() ).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class with member functions: typedef std::function<bool (const std::string &)> InsertFunction; bool insertSourceFile(
I have an inline member function defined under class MyClass int MyClass::myInlineFunction(); This function
Say I have a type with a member function: class Thing { std::string m_name;
I have a std::atomic which contains a pointer to a member function. Everything compiles
Class member functions in Python have to explicitly declare a self parameter which represents
For example, I have a class foo with some member functions.. within some function
Does a class have to allocate memory for its non-static member functions every time
I have a member function in a class that has a callback, but the
Imagine I have a class Window with a member function show which causes the
I have a class ( EAGLView ) which calls a member function of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.