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

  • Home
  • SEARCH
  • 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 6907761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:28:32+00:00 2026-05-27T08:28:32+00:00

As I understand it, methods are really just functions with an implicit extra parameter

  • 0

As I understand it, methods are really just functions with an implicit extra parameter (the this pointer), and static methods are the pretty much the same as free functions.

But there seem to be some differences between methods and functions; for example, when passing a function as an argument, why does the reference operator & have to be used on methods, but not on free functions?

foobar(&MyClass::method);
goobar(freefunction);

What other subtle technical differences are there between methods and free functions?

  • 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-05-27T08:28:33+00:00Added an answer on May 27, 2026 at 8:28 am

    In:

    foobar(&MyClass::method);

    … & is not the “reference operator” but is the address-of operator. It takes the address of its operand.

    You actually do still “have to” take the address of a free function in code such as (although implicit conversions are available):

    goobar(freefunction);
    

    There are implicit conversions available which will cause an expression such as Foo to decay in to a pointer, but I have had much difficulty in getting GCC to accept such code error- and warning-free, in cases where MSVC has no problems.

    Aside from this, there are two main differences between free functions and non-static member functions:

    1. Non-static member functions operate on an instance of a class, and there is a this pointer which points to the class itself.
    2. The syntax for creating and calling through a pointer-to-free-function is different than that for a pointer-to-member-function.

    In the case of the free function, the syntax is trivial(ish):

    void foo();  // Function declaration
    void(*f)();  // Declaration of pointer-to-function-returning-void-and-taking-no-parameters
    

    But in the case of a pointer to a member function, the syntax is much trickier:

    struct Bar
    {
      void DoIt()
      {
      }
      void DoThat(int n)
      {
        n;
      }
    };
    
    
    void(Bar::*thatfn)(int);    // declares a pointer-to-member-function taking int returning nothing
    thatfn = &Bar::DoThat;      // initializes pointer to point to DoThat(int)
    (bar.*thatfn)(42);          // call the function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read this a lot in many JavaScript introductions. I just don't understand it.
I understand that these methods are for pickling/unpickling and have no relation to the
Long methods are evil on several grounds: They're hard to understand They're hard to
I understand how the new keyword can hide methods in a derived class. However,
I understand (I think) the basic idea behind RESTful-ness. Use HTTP methods semantically -
I understand that static method inheritance is not supported in C#. I have also
I am learning rails and going back to ruby to understand how methods in
I'm really rolling up my sleeves and trying to understand Java annotations for the
Ok, this is really difficult to confess, but I do have a strong temptation
My understanding of symfony isn't stellar sometimes. I just came across this problem and

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.