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 8471275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:45:07+00:00 2026-06-10T16:45:07+00:00

Possible Duplicate: how to specify a pointer to an overloaded function? I have a

  • 0

Possible Duplicate:
how to specify a pointer to an overloaded function?

I have a library which has a class defined as:

struct ClassA
{
    static ClassA foo(long);
    static ClassA foo(double);
}

I need to get the addresses of both of those functions. The code I am currently trying gives error C2440: cannot convert from ‘overloaded-function’ to ‘…’

ns::ClassA (ns::ClassA::*ClassA_foo1)(long) = &ns::ClassA::foo;
ns::ClassA (ns::ClassA::*ClassA_foo2)(double) = &ns::ClassA::foo;

I thought it might be the fact that they are static, but placing static either before or after the return type gives the same error.

  • 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-10T16:45:09+00:00Added an answer on June 10, 2026 at 4:45 pm

    The fact that the function is overloaded is not really relevant. The real issue here is the difference between a function-pointer and a member-function-pointer. I’ll run through some examples without overloading.

    Solution: Either remove the static, in order to define them as member-functions. Or else replace ns::ClassA::*ClassA_foo1 with *ClassA_foo1. I think you want the latter. (But I actually recommend you use typedef, as others have already suggested).

    Consider these two:

    namespace ns {
    struct ClassA
    {
        static ClassA foo(long);
    };
    }
    

    and

    namespace ns {
    struct ClassA
    {
        ClassA foo(long);
    };
    }
    

    In the former case, foo is static and is therefore a typical function, and can be stored in a function-pointer:

    ns::ClassA (ClassA_foo1)(long) = &ns::ClassA::foo;
    

    If you remove the static, then it is not a function any more, it’s a member function. And pointers-to-member-functions are different from pointers-to-functions, they must be executed with an object that will be the this object on which the method is called.

    The type of a function pointer includes the type of the return value and the type of the parameters. But the type of a pointer-to-member-function must also include the type of the this object – you wouldn’t expect to be able to run a method from a Circle on an object of type BankAccount.

    Declaring a pointer-to-function:

     ReturnType (*variable_name) (PARAM1, PARAM2)
    

    Declaring a pointer-to-member-function:

     ReturnType (ThisObjectType::*variable_name) (PARAM1, PARAM2)
    

    This last line is the interesting one. At first glance, you might think that R (A::*v) (P1,P2) declares a normal function-pointer and places the resulting variable v into the A scope. But it does not. Instead it defines a pointer-to-member-function which operates on objects of type A.

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

Sidebar

Related Questions

Possible Duplicate: Creating a custom Document Library in SharePoint I have 2 users, Martin
Possible Duplicate: Specify Command for MenuItem in a DataTemplate I have a collection of
Possible Duplicate: class System.Random .. why not static? Following on from Generated random numbers
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: How do I specify the equivalent of volatile in VB.net? What is
Possible Duplicate: How can I specify the latest time of day with DateTime I
Possible Duplicate: When do I need to specify the JavaScript protocol? for example <body
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Mysql Offset Infinite rows Is it possible to specify a query in
Possible Duplicate: Including FSharp.Core in a C# project: resolving type collisions I have referenced

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.