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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:35:57+00:00 2026-06-13T17:35:57+00:00

I have the following code: #include <iostream> using namespace std; class A { int

  • 0

I have the following code:

#include <iostream>
using namespace std;

class A
{
    int m_value;
public:
    A(int value)
    {
        m_value = value;
        funcA(&A::param);
    }

    void funcA(void (A::*function)(int))
    {
        (this->*function)(m_value);
    }

    void param(int i)
    {
        cout << "i = " << i << endl;
    }
};


int main()
{
    A ob(10);

    return 0;
}

I have a class in which I call a function that receives another function as parameter. The function call is at line funcA(&A::param). What I want is to be able to pass a function as parameter without being necessary to specify the class scope: funcA(&param). Also I didn’t want to use typedefs that’s why I have the code a little ‘dirty’.

Is there any possibility to achieve 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-06-13T17:35:58+00:00Added an answer on June 13, 2026 at 5:35 pm

    This cannot be done. A function pointer in a class must be identified using the class scope (A::function)

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

Sidebar

Related Questions

I have following code: #include <iostream> using namespace std; template<class T> T max(T *data,int
I have the following code #include <iostream> using namespace std; class Object { public:
I have the following code: #include <iostream> using namespace std; class testing{ int test()
I have the following code #include <iostream> #include <vector> using namespace std; int distance(vector<int>&
I have the following code compiled by gcc: #include <iostream> using namespace std; class
I have the following code: #include<iostream> using namespace std; typedef void (*HandlerFunc)(int, int); HandlerFunc
i have following code #include <iostream> #include <utility> using namespace std; namespace rel_ops{ template<class
I have the following C++ code: #include <iostream> #include <vector> using namespace std; class
I have written the following code: #include <iostream> using namespace std; template <class T>
I have the following code: #include <iostream> #include <stdio.h> using namespace std; template <class

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.