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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:01:21+00:00 2026-06-16T20:01:21+00:00

I will do my best to explain this as clearly as possible. My example

  • 0

I will do my best to explain this as clearly as possible.

My example currently involves 3 different classes.

  1. My model class (lets call it MyModel.cpp)
  2. My data class that MyModel has an object of (MyData.cpp)
  3. My undo redo class that modifies my model (MyModelUR.cpp)

MyModel has a MyData object. MyData contains a bunch of doubles each with its own get and set function. The way my system works is the setter is called by calling redo() in MyModelUR. This redo() function is called in MyModel when a change is detected. This is outside the scope of the problem though.

MyModelUR has 3 functions, a constructor which takes a few args, undo() and redo() which are NOT allowed to take any args.

What happens is, I want MyModel to pass a function pointer of the desired setter in MyData to MyModelUR.

So, that means the constructor for MyModelUR needs to take a function pointer as an arg and then store it in a private global variable. So far I have something like this…

MyModelUR::MyModelUR(MyModel* model, double newValue, void (*function)(double))
{
    Model = model;

    NewValue = newValue;

    //FunctionToCall is a void*
    FunctionToCall = &function;
}

Now, in my redo() function, I want to use FunctionToCall…I’m trying to do this but it’s not working and just giving me compiling errors…

MyModelUR::redo()
{
    Model->data()->FunctionToCall(NewValue);
}

I want to implement it this way so I don’t need X number of undo()/redo() functions for each double in MyData.

I appreciate your help and suggestions, but I have a few restrictions when considering replies like, I want to use this architecture due to some other constraints I have, and I can’t use Boost libraries.

TLDR; I want to call a void function pointer which takes a double in a separate class that’s being called on an object.

Thank you!

EDIT: After the comments below this is what I’m working with…

MyModelUR::MyModelUR(MyModel* model, double newValue, void (MyModel::*function)(double)) :
    Model(model),
    NewValue(newValue),
    FunctionToCall(function)
{
}

void MyModelUR::redo()
{
    MyData data = Model->data();

    data.*FunctionToCall(NewValue);
}

However, this throws the error on the 2nd line of code in redo() that says: “must use ‘.‘ or ‘->‘ to call pointer-to-member function in …”

  • 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-16T20:01:22+00:00Added an answer on June 16, 2026 at 8:01 pm

    Firstly, your function pointer should be a method pointer, and you’re trying to use a free-function pointer.

    Secondly, don’t try to store this as a void*, it isn’t guaranteed to be the same size. Just declare it as a method pointer and stop casting.

    Lastly, you’re currently storing (in your void*) the address of the transient function pointer argument, which will be invalid even if it were the right type.

    Your code should end up something like this:

    class MyModelUR {
        ...
        MyModel *Model;
        double NewValue;
        void (MyData::*FunctionToCall)(double);
        ...
        MyModelUR(MyModel* model, double newValue, void (MyData::*function)(double))
          : Model(model), NewValue(newValue), FunctionToCall(function)
        {}
        void redo() {
            MyData &data = Model->data();
            (data.*FunctionToCall)(NewValue);
        }
    };
    

    Instantiate one of these like:

    MyModelUR *ur = new MyModelUR(model, 3.4, &MyData::setSomeValue);
    

    Functional note: you’ll need a getter method pointer and somewhere to store the old value as well, if you want undo.

    Aesthetic note: initial uppercase member names are horrible, it’s the same scheme you’re using for types. Just IMO.

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

Sidebar

Related Questions

Sorry in advance if I don't explain this clearly. I will try my best
I hope I can explain this clearly. I have a table, lets call it
This problem is a little different, so I will try my best to explain
I will do my best to explain this. Hopefully my notes in script will
I'm going to try to explain this best I can I will provide more
I will try and explain this the best way I can. I have a
I will try to explain this as best as I can and hope someone
Hi I will try explain this as best I can. I am using a
This is a bit tricky to explain but I will try my best to
Ok, let me try and explain this to the best of my ability. Lets

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.