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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:53:54+00:00 2026-06-08T01:53:54+00:00

I have this code that defines struct (incoming is simple struct) #define FUNCS_ARRAY 3

  • 0

I have this code that defines struct (incoming is simple struct)

#define FUNCS_ARRAY 3

    struct func
    {
        void (AA::*f) (incoming *);
        int arg_length;
    };

    func funcs[FUNCS_ARRAY];

then in class AA body i define the pointer Array like this :

funcs[0] = { &AA::func1, 4 };
funcs[1] = { &AA::func2, 10 };
funcs[2] = { &AA::func2, 4 };

when i try to call one of the functions via the array im getting compilation error:
if i call it like this (p is incoming ):

(*funcs[p->req]->*f)(p);  

im getting this error:

error: no match for ‘operator*’ in ‘*((AA*)this)->AA::funcs[((int)p->AA::incoming::req)]’

when i try to call it like this :
(funcs[p->req]->*f)(p);
im getting :

error: ‘f’ was not declared in this scope

when i try this :

   (funcs[p->req].f)(p);

error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((AA*)this)->AA::funcs[((int)p->AA::incoming::req)].AA::func::f (...)’, e.g. ‘(... ->* ((AA*)this)->AA::funcs[((int)p->AA::incoming::req)].AA::func::f) (...)’

what is the right way to access the function pointer in side the struct ?

  • 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-08T01:53:56+00:00Added an answer on June 8, 2026 at 1:53 am

    To call a member function through a pointer-to-member-function you need that pointer and an instance of the appropriate class.

    In your case, the pointer-to-member is funcs[i].f, and I’ll assume you have an instance of AA called aa. Then you can call that function like this:

    (aa.*(funcs[p->req].f))(p);
    

    If aa is a pointer-to-AA, then the syntax would be:

    (aa->*(funcs[p->req].f))(p);
    

    If you’re calling from within a (non-static) member function of AA, then try:

    (this->*(funcs[p->req].f))(p);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some Objective-C code that looks like this: #define myVar 10 float f
I have some legacy code that contains this typedef: typedef enum simple_op_enum { #define
I have this code in linux kernel: #define task_cred_xxx(task, xxx) ({ __typeof__(((struct cred *)NULL)->xxx)
I have a lot of code like this: #define WITH_FEATURE_X struct A { #ifdef
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
I have this code that runs but never stops. class A { public static
I have this code that reads from XML file. It gets five strings (groupId,
I have this code that suppose to place the marker by the latlng public
I have this code that where I would normally use one line: if (tableView
I have this code that works in a unit test but doesn't work when

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.