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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:32:54+00:00 2026-05-15T07:32:54+00:00

I have an generic math-method, that operates under a set of functions (with a

  • 0

I have an generic math-method, that operates under a set of functions (with a lot of variables and states, so it can’t be static). I’ve implemented method in parent class and I want to declare a different set of functions in every child-class.
I’ve try to do something like this:

class A {
public:
    typedef int (A::*func)();
    func * fs;
    void f() { /*call functions from this->fs*/ }
};

class B : public A {
public:
    int smth;

    B(int smth) {
         this->smth = smth; //user-provided variables

        //there may be a lot of functions with same interface
        this->fs = new func[1];
        fs[0] = &B::f;
    }

    int f() {
        return smth + 1;
    }
};

It fails with this error:
error C2440: ‘=’ : cannot convert from ‘int (__thiscall B::* )(void)’ to ‘A::func’

Or “IntelliSense: a pointer to a bound function may only be used to call the function” if I try to use &this->f;

  • 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-15T07:32:54+00:00Added an answer on May 15, 2026 at 7:32 am

    Curiously recurring template pattern would help.

    template<typename Derived>
    class A {
    public:
        typedef int (Derived::*func)();
        func * fs;
        void f()
        {
            Derived* const This = static_cast<Derived*>(this);
            /* call functions like (This->*(fs[0]))() */
        }
    };
    
    class B : public A<B> {
    public:
        int smth;
    
        B(int smth) {
             this->smth = smth; //user-provided variables
    
            //there may be a lot of functions with same interface
            this->fs = new func[1];
            fs[0] = &B::f;
        }
    
        int f() {
            return smth + 1;
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generic Print method that iterates over a list and simply prints
I have generic list which must be a preserved order so I can retrieve
I have generic type that looks like: public class GenericClass<T, U> where T :
I have a generic linked-list that holds data of type void* I am trying
I have a Generic Base Class that I want to allow one of two
I have a method that converts an int to a base60 string (using 0-9,
i have the following code that won't compile because of generic problems. It comes
I have a list-generic that has a property (class type). I need a sort
While writing several math utilities I bumped into need to implement generic utility that
Suppose I have a static class in C#: public static class Math { [Microsoft.SqlServer.Server.SqlFunction]

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.