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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:19:58+00:00 2026-06-09T13:19:58+00:00

I am new to function pointers and I would like your help. I am

  • 0

I am new to function pointers and I would like your help.
I am having a method:

int test3(int i)
{
    return i;
}

Then in another method(not main) I do:

int (*pTest3)(int) = test3;

From the examples that I have read this seems ok.
However, I get a compile time error:

testFile.cpp:277:25: error: argument of type ‘int
({anonymous}::CheckingConsumer::)(int)’ does not match ‘int (*)(int)’

I do not understand what is wrong. Any help would be appreciated.

Thanks a lot.

  • 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-09T13:19:59+00:00Added an answer on June 9, 2026 at 1:19 pm

    Your test3 is a member function of a struct or a class. Class member functions have a hidden this parameter passed into them and so cannot be used with plain function pointers. You need to either declare the function as static or move it outside the struct/class, so that it no longer has a hidden this parameter, or use a class method pointer instead of a function pointer:

    // static class method:
    class X
    {
        static int test3(int i)
        {
            ...
        }
    };
    
    // Non-class method, at global scope
    int test3(int i)
    {
        ...
    }
    
    // Class method pointer
    class X
    {
        int test3(int i)
        {
            ...
        }
    };
    
    // Create the method pointer
    int (X::*pTest3) = &X::test3;
    X *obj;
    // Call the method pointer on an object
    (obj ->* pTest3)(42);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to temporarily override the kill-new function. I have a way I
Firstly, I am very new to function pointers and their horrible syntax so play
I'm fairly new to C++ and don't quite understand function parameters with pointers and
C++11 supports a new function syntax: auto func_name(int x, int y) -> int; Currently
I want to use a function from another class within a new function which
This link shows you that jQuery uses (new Function(return + data))(); for older browsers,
I would like to implement a function that takes as input a size n
I'm a bit confused with these C++ pointers and I would like to know
I would like to have a function that returns something like an array of
I would like to ask question regarding pointers. I dont know what to do

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.