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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:26:54+00:00 2026-06-03T02:26:54+00:00

I am trying to make an array of pointer to private member functions. The

  • 0

I am trying to make an array of pointer to private member functions. The array itself is private, so I don’t see why it says:

error: ‘void Foo::foo1(int)’ is private

This works:

class Foo {
    public:
        Foo();
        void foo1(int);
        void foo2(int);

    private:
        void (Foo::*someMethods[])(int);
        void foo3(int);

};

Foo::Foo() {}

void (Foo::*someMethods[])(int) = {&Foo::foo1, &Foo::foo2};

void Foo::foo1(int) {}
void Foo::foo2(int) {}
void Foo::foo3(int) {}

This does not work:

class Foo {
    public:
        Foo();

    private:
        void (Foo::*someMethods[])(int);
        void foo1(int);
        void foo2(int);
        void foo3(int);

};

Foo::Foo() {}

void (Foo::*someMethods[])(int) = {&Foo::foo1, &Foo::foo2};

void Foo::foo1(int) {}
void Foo::foo2(int) {}
void Foo::foo3(int) {}
  • 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-03T02:26:56+00:00Added an answer on June 3, 2026 at 2:26 am

    Your declaration

    void (Foo::*someMethods[])(int);
    

    inside class Foo and

    void (Foo::*someMethods[])(int) = {&Foo::foo1, &Foo::foo2};
    

    are completely unrelated arrays. The latter is a global variable. Also, zero-length arrays are illegal in C++, if you are using gcc, compile with -pedantic and it should give you a warning.

    If you were to access the array declared in Foo you would use the following:

    void (Foo::*(Foo::someMethods)[])(int) = {&Foo::foo1, &Foo::foo2};
    

    However, you can only initialize members that are static outside the class, so the following code would work:

    class Foo {
        public:
            Foo();
    
        private:
            static void (Foo::*someMethods[])(int);
            void foo3(int);
            void foo1(int);
            void foo2(int);
    
    };
    
    Foo::Foo() {}
    
    void (Foo::*(Foo::someMethods)[])(int) = {&Foo::foo1, &Foo::foo2};
    
    void Foo::foo1(int) {}
    void Foo::foo2(int) {}
    void Foo::foo3(int) {}
    
    int main(){}
    

    Or your other option is to move the non-static member in the constructor as you said in the comments. But, you should add the size of the array to be conforming.

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

Sidebar

Related Questions

I'm writing some error checking and trying to make use of an boolean array
I'm trying to make a pointer point to a 2D array of pointers. What
I'm trying to make an array of structs where each struct represents a celestial
I was trying to make an array-based linear list, then I compiled this: char
I am trying to make an array of strings and then pluck a random
I'm trying to make a dynamic array in C# but I get an annoying
I'm trying to subclass Array in ruby to make it randomize its elements when
consider the code below, Am trying to make a Sparse_matrix that contains an array
I am trying to make a mouse roll-over. i.e when user places the pointer
I am trying to create a property that will make a pointer (byte*) from

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.