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

The Archive Base Latest Questions

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

Now how about a class’s function pointer to another class’s function? That’s my question

  • 0

Now how about a class’s function pointer to another class’s function? That’s my question

Example:

class Apple
{
   int(Apple::*pActionFunc)(void);
};

class Tree
{
   Apple* tempy;

   void Init( void );

   int I_Work( void );
};

void Tree::Init( void )
{
  tempy = new Apple( );
  tempy->pActionFunc = &Tree::I_Work;
}

int Tree::I_Work( void )
{
   "Do Things"
}

That will not work. Why is that?

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

    This will not work, because like all variables function pointers also have an type and you can only use an pointer to same type to store address of an variable type.

    int(Apple::*pActionFunc)(void); 
    

    Tells the compiler that pActionFunc is a pointer to an member function of Apple class which takes void as an parameter and returns an int.

    tempy->pActionFunc = &Tree::I_Work;
    

    Tries to store the address of an function I_Work() which is member of Tree class an which takes void as input parameter and returns an int.

    If you notice they are members functions of different classes and hence the error.

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

Sidebar

Related Questions

I have a question about parcelable class (android). Until now, I have passed a
I'm learning about C++ in a class right now and I don't quite grok
I'm reading some tutorials now about jQuery.. function creating,plugin creation etc. but these tutorials
I am just now learning about function pointers and, as I was reading the
I have next class and try to declare member function which will return pointer
I have two classes that don't know anything about themselfs class A, class B.
For example I have a class that builds the GUI, a class that handles
I have some question about arrays, I'm reading some book about Java, and now
I've asked a question about this class before, but here is one again. I've
Just a quick question about the Timer class of Flex 4. I have a

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.