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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:01:25+00:00 2026-05-25T16:01:25+00:00

I have an algorithm that calls several functions to process its data. Each of

  • 0

I have an algorithm that calls several functions to process its data. Each of these functions share and manipulate many of the same variables. Therefore I’m trying to avoid having a set of functions that contain a long list of reference arguments as I find that to become very difficult to read, especially since many of these variables are STL containers. As a result, I have implemented a functor to perform the work of the algorithm and defined a function wrapper for the functor, as shown below

class myfunctor {
private:
   ... list of shared members ...

   void A(..args..) { ..do some work on shared members.. } 
   void B(..args..) { ..do some work on shared members.. }
   void C(..args..) { ..do some work on shared members.. }

public:
   void operator()(class1& X, class2& Y) {
      A( .. );
      ..
      B( .. );
      ..
      C( .. );
      ..etc.. 
   }
};

void algorithm(class1& X, class2& Y) {
    myfunctor obj;
    obj(X, Y);
}

I’m just curious to see if there is perhaps a better way of implementing several functions that all depend on the same variables, and if this is considered bad practice?

  • 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-25T16:01:26+00:00Added an answer on May 25, 2026 at 4:01 pm

    With umpteen functions working on the same shared data, making them member functions of a class with the data as instance data is the rational choice.

    However, “functor” is perhaps not the correct term for your beastie.

    A functor behaves much like a simple function pointer: it can be freely copied around, and usually, from the caller’s point of view, doesn’t appear to change state. While your beastie apparently cannot be freely copied around, and does appear to change state. I’d say your beastie is more like a state machine object, brought from state to state by the function calls.

    Cheers & hth.,

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

Sidebar

Related Questions

I have an algorithm that uses the following OpenSSL calls: HMAC_update() / HMAC_final() //
I have an algorithm that generates strings based on a list of input words.
I have an algorithm that recursively makes change in the following manner: public static
I have this algorithm that I want to implement on VB6. Sub Main() dim
If I have an algorithm that takes n log n steps (e.g. heapsort), where
I have a two part question Best-Practice I have an algorithm that performs some
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
I have a SP that has the following algorithm. IF <SomeCondition> BEGIN SELECT *
Does anybody have any reference material that details Cauchy-Reed algorithm? Googling for Cauchy-Reed Solomon
i have heard from a friend of mine that the best algorithm for swapping

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.