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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:14:35+00:00 2026-05-22T23:14:35+00:00

Expanding on this question , it looks like I did not provide enough detail.

  • 0

Expanding on this question, it looks like I did not provide enough detail.

I have an object called CallbackObject that is designed to contain an object instance, and the information of what function to invoke, and the parameters to pass at invokation time.

template <typename objectType,
          typename memberFunctionPtrType,
          typename memberFcnArg1Type>
struct CallbackObject1
{
  objectType obj ;
  memberFunctionPtrType fcnPtr ;
  memberFcnArg1Type arg1 ;

  CallbackObject1(objectType iObj,
                  memberFunctionPtrType iFcnPtr,
                  memberFcnArg1Type iArg1 )
  {
    obj = iObj ;
    fcnPtr = iFcnPtr ;
    arg1 = iArg1 ;
  }

  void exec()
  {
    (obj.*fcnPtr)( arg1 ) ;
  }
} ;

Example of use:

struct Point
{
  float x,y ;
  void print( int numTimes )
  {
    for( int i = 0 ; i < numTimes ; i++ )
      printf( "%f %f\n", x, y ) ;
  }
} ;

typedef void (Point::* PointPrintFcnType)( int ) ;

int main()
{
  Point p ;
  p.x=p.y=1;

  CallbackObject1<Point, PointPrintFcnType, int> ocall( p, &Point::print, 5 );
  ocall.exec() ;
}

The only problem I’m having is if objectType is a pointer type, then (obj.*fcnPtr) fails, since it should really read ( (*obj).*fcnPtr) or (obj->*fcnPtr) if obj is a pointer.

Now I have one solution, where I define another CallbackObject class like so:

template <typename pObjectType,
          typename memberFunctionPtrType,
          typename memberFcnArg1Type>
struct CallbackPObject1
{
  pObjectType obj ;
  memberFunctionPtrType fcnPtr ;
  memberFcnArg1Type arg1 ;

  CallbackPObject1(pObjectType iObj,
                  memberFunctionPtrType iFcnPtr,
                  memberFcnArg1Type iArg1 )
  {
    obj = iObj ;
    fcnPtr = iFcnPtr ;
    arg1 = iArg1 ;
  }

  void exec()
  {
    (obj->*fcnPtr)( arg1 ) ;
  }
} ;

But this is crufty at best, and difficult to use at worst, if someone else is using this code, they will have to create a different kind of Callback object if the object type being used is actually a pointer.

Is there any way around this?

  • 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-22T23:14:36+00:00Added an answer on May 22, 2026 at 11:14 pm

    Here’s an example helper function, assuming void return, one argument, and no need to handle more than one level of indirection:

    template <typename T, typename F, typename A>
    inline void invoke(T& obj, F func, const A& arg)
    {
        (obj.*func)(arg);
    }
    
    template <typename T, typename F, typename A>
    inline void invoke(T* obj, F func, const A& arg)
    {
        (obj->*func)(arg);
    }
    

    If you need to handle more than one level of indirection, you can replace the second function with this:

    template <typename T, typename F, typename A>
    inline void invoke(T* obj, F func, const A& arg)
    {
        invoke(*obj, func, arg);
    }
    

    This will recursively strip off levels of indirection until you end up with something that you can invoke your member function on.

    You can then write your exec() function like so:

    void exec()
    {
        invoke(obj, fcnPtr, arg1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Expanding on this question , For items that trigger dialogs and menus (i.e. non
I have searched the numerous questions that look like this one, but haven't found
Expanding on Jon Skeet's answer to This Previous Question . Skeet doesn't address the
This question is expanding on another I had gotten help with via Stackoverflow (
Let me preface this question by stating that i don't usually condone the practice
More often than not we need loops like this do { Type value(GetCurrentValue()); Process(value);
I've seen many questions like this but none of them seem to have position:absolute
I am working on a profit and loss report that should look like this:
I’ve created a menu in page.xml and it looks like this: <reference name=primary.menu> <action
I have this sudden out of the blue requirement for extending a part of

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.