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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:12:13+00:00 2026-05-10T16:12:13+00:00

I am trying to pass a member function within a class to a function

  • 0

I am trying to pass a member function within a class to a function that takes a member function class pointer. The problem I am having is that I am not sure how to properly do this within the class using the this pointer. Does anyone have suggestions?

Here is a copy of the class that is passing the member function:

class testMenu : public MenuScreen{ public:  bool draw;  MenuButton<testMenu> x;  testMenu():MenuScreen('testMenu'){     x.SetButton(100,100,TEXT('buttonNormal.png'),TEXT('buttonHover.png'),TEXT('buttonPressed.png'),100,40,&this->test2);      draw = false; }  void test2(){     draw = true; } }; 

The function x.SetButton(…) is contained in another class, where ‘object’ is a template.

void SetButton(int xPos, int yPos, LPCWSTR normalFilePath, LPCWSTR hoverFilePath, LPCWSTR pressedFilePath, int Width, int Height, void (object::*ButtonFunc)()) {      BUTTON::SetButton(xPos, yPos, normalFilePath, hoverFilePath, pressedFilePath, Width, Height);      this->ButtonFunc = &ButtonFunc; } 

If anyone has any advice on how I can properly send this function so that I can use it later.

  • 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. 2026-05-10T16:12:13+00:00Added an answer on May 10, 2026 at 4:12 pm

    To call a member function by pointer, you need two things: A pointer to the object and a pointer to the function. You need both in MenuButton::SetButton()

    template <class object> void MenuButton::SetButton(int xPos, int yPos, LPCWSTR normalFilePath,         LPCWSTR hoverFilePath, LPCWSTR pressedFilePath,         int Width, int Height, object *ButtonObj, void (object::*ButtonFunc)()) {   BUTTON::SetButton(xPos, yPos, normalFilePath, hoverFilePath, pressedFilePath, Width, Height);    this->ButtonObj = ButtonObj;   this->ButtonFunc = ButtonFunc; } 

    Then you can invoke the function using both pointers:

    ((ButtonObj)->*(ButtonFunc))(); 

    Don’t forget to pass the pointer to your object to MenuButton::SetButton():

    testMenu::testMenu()   :MenuScreen('testMenu') {   x.SetButton(100,100,TEXT('buttonNormal.png'), TEXT('buttonHover.png'),         TEXT('buttonPressed.png'), 100, 40, this, test2);   draw = false; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 191k
  • Answers 191k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try checking if the image has the selected class before… May 12, 2026 at 6:13 pm
  • Editorial Team
    Editorial Team added an answer Yes, take a look at my answer to this question.… May 12, 2026 at 6:13 pm
  • Editorial Team
    Editorial Team added an answer I don't have extensive knowledge of the Google maps Api… May 12, 2026 at 6:13 pm

Related Questions

I am new to php and trying to write a login function. Bit stuck
I am trying to pass JSON data from the client browser to an ASP.NET
I'm trying to create am immutable type (class) in C++, I made it so
I'm working with MVC recently and I've encountered a strange problem while trying to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.