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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:39:58+00:00 2026-06-04T10:39:58+00:00

I want to do the following :- #include <iostream> template <typename I> class A

  • 0

I want to do the following :-

#include <iostream>

template <typename I>
class A {
  public:
    I member_;
    void f() {}
    void g() {}
    typedef void (A::*fptr) ();
    static const fptr arr[];
};

template <typename I>
A<I>::fptr A<I>::arr[] = {
  &A<I>::f,
  &A<I>::g
};

How do I do this?
I get the following errors :-

g++ memeber_func_ptr_array.cpp 
memeber_func_ptr_array.cpp:14:1: error: need ‘typename’ before ‘A<I>::fptr’ because ‘A<I>’ is a dependent scope
memeber_func_ptr_array.cpp:17:2: error: expected unqualified-id before ‘;’ token
  • 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-04T10:39:59+00:00Added an answer on June 4, 2026 at 10:39 am

    Two things.

    1. fptr is a dependent type so you need typename:

      template <typename I>
      const typename A<I>::fptr A<I>::arr[2] = { // also note the 2 and the const
        &A<I>::f,
        &A<I>::g
      };
      

      And as jrok noted in the comments, your declaration is const so the definition must be const as well.

    2. Client code (files that just include the header) needs to know how big the array is so you need the actual size of the array in the declaration:

      static const fptr arr[2]; // include size
      

      You can only use the automatic deduction of the size of the array when the array is declared and initialised in the same place.

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

Sidebar

Related Questions

I have the following code: #include <iostream> class Grandma { public: virtual void foo()
I have the following code #include <iostream> #include <vector> class Entity { public: virtual
Is there a better way to do the following? #include <iostream> template <typename T>
Consider the following code : #include <vector> #include <iostream> class a { public: int
In the sample: #include <iostream> using namespace std; class B { public: virtual void
There is such code: #include <iostream> #include <vector> template <class T> class A{ public:
I have a question about the following code: #include <iostream> #include <boost/scoped_ptr.hpp> class Interface
I have a situation that looks like the following code: #include <iostream> class A
Consider following example: #include <iostream> #include <functional> #include <algorithm> #include <vector> #include <boost/bind.hpp> const
assume the following class is given: class Base{ public: Base() {} Base( const Base&

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.