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

The Archive Base Latest Questions

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

I have a function Foo and a class CDelegate. typedef void (*typeFctPtr)(void*); void Foo(void*

  • 0

I have a function Foo and a class CDelegate.

typedef void (*typeFctPtr)(void*);


void Foo(void* dummy)
{
  cout << "Foo\n";
}


class CDelegate 
{ 
  public:

  CDelegate (const typeFctPtr& f_ref_Wrapper, void* f_pvSubscriber) 
    : m_ref_Wrapper(f_ref_Wrapper), m_pvSubscriber(f_pvSubscriber) 
  {
  }

  inline void operator () () const
  {
    (*m_ref_Wrapper)(0);
  }

  inline void operator=(const CInterruptDelegate& D)
  {
  }

private:
  void* m_pvSubscriber;
  const typeFctPtr& m_ref_Wrapper;
};

A second class has a static member static CDelegate m_Delegate; which I initialize using the constructor like this:

CInterruptDelegate CSpi1::m_Delegate(FreeFunction, 0);

I want to call Foo by calling the ()operator of my static object: CSpi1::m_Delegate();

I get an exception at (*m_ref_Wrapper)(0);
Is there something wrong with the syntax? I am not quite sure if what I try to do is possible at all. I have a working solution where the constructor of CDelegatedoes not take a const reference of a function pointer but the function pointer itself. I can then call the function in the ()operator without problems. I want to use a const reference because the function pointer call cannot be optimized and I hope the call via the const reference can because everything should be known at compile time.

  • 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:09:55+00:00Added an answer on May 23, 2026 at 2:09 pm

    You’re holding a reference to a pointer to a function (and the pointer is a temporary which has been destroyed by the time you use it, so things go badly wrong).

    Try changing your typedef to be a function type:

    typedef void typeFct(void*);
    ...
    const typeFct & m_ref_Wrapper;
    

    Then with your existing code you’ll end up with a reference to a function, and you’ll be fine. Or you could store a pointer to the function – const typeFct *.

    And in either case the call can just be m_ref_Wrapper(0).

    In general I prefer to typedef function types rather than pointer-to or reference-to, if only because the syntax is less ugly.

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

Sidebar

Related Questions

Let's assume we have a template function foo: template<class T> void foo(T arg) {
You have a static function: public static function foo() In the same class you
Let's say I have a class with the function class foo { ... void
Suppose I have virtual function foo() in class B, and I need slightly different
I have class Foo(): function bar(): pass function foobar(): pass Rather than executing each
I have a function that accepts a variable number of parameters: foo (Class... types);
I have a base class Foo that has an Update() function, which I want
Say I have a function foo: (defun foo (x y &rest args) ...) And
I have this class: class Foo : IDisposable { SomeBigResource resource; void UsingResource() {
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)

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.