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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:02:34+00:00 2026-06-01T22:02:34+00:00

For structural reasons, I’d like to be able to pass an instance of a

  • 0

For structural reasons, I’d like to be able to pass an instance of a functor to another functor. At the moment I achieve something equivalent by handing a pointer to a function to my functor.

I’ve attempted to encapsulate the idea in some minimal code below:

class A
{
private:
    double _x, _y, _z;

public:
    A (double x, double y, double z) : _x(x), _y(y), _z(z) {};

    void operator() (double t) const
    {
        // Some stuff in here that uses _x, _y, _z, and t.
    }
};

class B
{
private:
    // What is the type of the functor instance?
    ??? A ???

public:
    // How do I pass the instance of A into B at initialisation?
    B (??? A ???) :  ??? : {};

    void operator() (double tau) const
    {
        // Something that uses an instance of A and tau.
    }
};

int main(void)
{
    // I want to do something like this:
    A Ainst(1.1, 2.2, 3.3); // Instance of A.
    B Binst(Ainst);         // Instance of B using instance of A.

    Binst(1.0);             // Use the instance of B.

    return 0
}

In essence, I want to be able to chain up functors. As stated above, I currently do this by passing a function pointer to B along with variables x, y, and z. In my code B is templated and the goal is to write it once and then reuse it without any modification later, which means that handing x, y, and z to B is not ideal. A on the other hand will be customised for each program that I write. I don’t mind B being quite messy, but I want A to be nice and clean as this is the part that will be exposed.

For those who know some quantum mechanics, B is the Schrödinger equation (or a master equation) and A is a time dependent Hamiltonian. The variables x, y, and z are used to construct the Hamiltonian, and t is time, allowing me to use the odeint library (so I’m using ublas and a couple of other Boost bits).

  • 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-01T22:02:35+00:00Added an answer on June 1, 2026 at 10:02 pm

    Using references?

    class A { /* ... */ };
    
    class B
    {
        A &a;
    
    public:
        B(const A &my_a)
            : a(my_a)
        { }
    
        // ...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What are the reasons a parallelized program doesn't achieve the ideal speedup? For example,
For various reasons, such as protecting investment, etc. I need to pass a series
I'm writing a structural modeling tool for a civil enginering application. I have one
I have a site nearing structural completion. Essentially, it's made up of Users and
As we know UML contains 13 types of diagrams (structural and behavioral) before starting
I'm looking for an add-in to VS2008 that can enable structural highlighting ( vertical
The structures of my Git repositories look like this: A-B-C-D-E-F # master branch in
In MySQL are there any restrictions (and/or) practical reasons against using a numbering system
I`m writing binary search tree template for two reasons - learning C++ and learning
I've a XHTML structure like this: <?xml version=1.0 encoding=utf-8 ?> <!DOCTYPE html PUBLIC -//W3C//DTD

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.