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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:16:31+00:00 2026-05-23T14:16:31+00:00

I recently found that function pointer syntax can be simplified when using the following

  • 0

I recently found that function pointer syntax can be simplified when using the following helper class:

template<typename Sig>
struct Fun {
    typedef Sig* Ptr;
};

It allows me a pointer to void() as follows:

typedef Fun<void()>::Ptr fun_ptr;
fun_ptr f = foo;

I would like to create a similar utility for to create a typedef to member function pointers. It would allow the following syntax:

struct Foo {
    void bar() {}
};

typedef MemFun<Foo, void()>::Ptr bar_type;
bar_type b = &Foo::bar;

However, I can’t figure out the typedef syntax:

template<class T, typename Sig>
struct MemFun {
    // How to use T and Sig to create member function typedef?
};

Can anyone help?

  • 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-23T14:16:32+00:00Added an answer on May 23, 2026 at 2:16 pm
    template<typename T, typename Sig>
    struct convenience {
        typedef Sig T::*type;
    };
    
    struct test {
        void member() {}
        void cmember() const {}
    };
    
    static_assert( std::is_same<
            convenience<test, void()>::type
            , decltype(&test::member)
        >::value, "Oops" );
    
    static_assert( std::is_same<
            convenience<test, void() const>::type
            , decltype(&test::cmember)
        >::value, "Oops" );
    

    When the Sig argument is a function type, the resulting type is a pointer to member function, not a pointer to data member. In particular, in this context function types like void() const are valid.

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

Sidebar

Related Questions

I recently found out that Javascript function can have classes, so I was wondering
Recently I found out that there are several things that one can do to
I've found recently that for some types of financial calculations that the following pattern
I've been using eval in my code and I recently found out that there
I recently found out that a method I've been using for validating user input
Recently I've found my self to implement code following a pattern like: public class
I'm currently using UKPhoneNumberField in one of my forms. I recently found that if
I recently found out that gcc allows the definition of nested function. In my
I am a windows dev, but I have recently found that I need to
I have recently found out that there exists a method called nth_element in the

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.