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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:55:07+00:00 2026-05-25T19:55:07+00:00

This list, has to hold functions, they might be from different namespaces and even

  • 0

This list, has to hold functions, they might be from different namespaces and even methods of instanced classes.
This list will then be iterated and all the functions and methods called. It would be nice if they could contain arguments also.

I was thinking on using a std::vector, but I suspect that I am far from correct in that guess.

What approach do you recommend me? All help is welcome.

  • 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-25T19:55:07+00:00Added an answer on May 25, 2026 at 7:55 pm

    Have all of your functions implement the Command Pattern.

    Your list becomes a

    std::list<Command>
    

    As you iterate over the list, you invoke the Execute() method of each list item.

    For example, say you have a simple Command interface called Commander:

    class Commander
    {
    public:
        virtual        ~Commander;
    
        virtual void    Execute();//= 0;
    };
    

    And you have three objects that you want to put in your list: A Greyhound, a Gyrefalcon, and a Girlfriend. Wrap each in a Commander object that calls the object’s function of interest. The Greyhound runs:

    class RunGreyhound: public Commander
    {
    public:
        void            Execute()
                        {
                            mGreyhound->Run();
                        }
    private:
        Greyhound*      mGreyhound;
    };
    

    The Gyrefalcon flies:

    class RunGyrefalcon: public Commander
    {
    public:
        void            Execute()
                        {
                            mGyrefalcon->Fly( mGyrefalcon->Prey() );
                        }    
    private:
        Gyrefalcon*      mGyrefalcon;
    };
    

    And the Girlfriend squawks:

    class RunGirlfriend: public Commander
    {
    public:
        void            Execute()
                        {
                            mGirlfriend->Squawk( mGirlfriend->MyJunk(), mGirlfriend->Mytrun() );
                        }
    private:
        Girlfriend*     mGirlfriend;
    };
    

    Stuff the Commander objects in your list. Now you can iterate over them and invoke each element’s Execute() method:

    std::list<Commander> cmdlist;
    
    RunGreyhound dog;
    cmdlist.push_back( dog );
    
    RunGyrefalcon bird;
    cmdlist.push_back( bird );
    
    RunGirlfriend gurl;
    cmdlist.push_back( gurl );
    
    for ( std::list<Commander>::iterator rit = cmdlist.begin(); rit != cmdlist.end(); ++rit )
    {
        rit->Execute();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This Wikipedia page has an extensive list of hashing methods As you can see,
I am new to SharePoint development. I have a list, this list has a
i have an IList<Animals> farmAnimals; this list has three types, Cows Sheep Chickens how
I have this html form which has options: <tr> <td width=30 height=35><font size=3>*List:</td> <td
Is this list-initialization of an array of unknown size valid in C++0x? int main()
Hello I have this list that i am working on. When i move the
I frequently find myself writing code like this: List<int> list = new List<int> {
Part of a programme builds this list, [u'1 x Affinity for war', u'1 x
I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
I am trying to do this: List<Parent> test = new List<Child>(); The complete code

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.