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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:39:53+00:00 2026-05-11T05:39:53+00:00

Is there a method/pattern/library to do something like that (in pseudo-code): task_queue.push_back(ObjectType object1, method1);

  • 0

Is there a method/pattern/library to do something like that (in pseudo-code):

task_queue.push_back(ObjectType object1, method1); task_queue.push_back(OtherObjectType object2, method2); 

so that I could do the something like:

for(int i=0; i<task_queue.size(); i++) {     task_queue[i].object -> method(); } 

so that it would call:

obj1.method1(); obj2.method2(); 

Or is that an impossible dream?

And if there’s a way to add a number of parameters to call – that would be the best.

Doug T. please see this Excellent answer!

Dave Van den Eynde‘s version works well too.

  • 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. 2026-05-11T05:39:53+00:00Added an answer on May 11, 2026 at 5:39 am

    Yes you would want to combine boost::bind and boost::functions its very powerful stuff.

    This version now compiles, thanks to Slava!

    #include <boost/function.hpp> #include <boost/bind.hpp> #include <iostream> #include <vector>  class CClass1 { public:     void AMethod(int i, float f) { std::cout << 'CClass1::AMethod(' << i <<');\n'; } };  class CClass2 { public:     void AnotherMethod(int i) { std::cout << 'CClass2::AnotherMethod(' << i <<');\n'; } };  int main() {     boost::function< void (int) > method1, method2;     CClass1 class1instance;     CClass2 class2instance;     method1 = boost::bind(&CClass1::AMethod, class1instance, _1, 6.0) ;     method2 = boost::bind(&CClass2::AnotherMethod, class2instance, _1) ;      // does class1instance.AMethod(5, 6.0)     method1(5);      // does class2instance.AMethod(5)     method2(5);       // stored in a vector of functions...     std::vector< boost::function<void(int)> > functionVec;     functionVec.push_back(method1);     functionVec.push_back(method2);      for ( int i = 0; i < functionVec.size(); ++i)     {                   functionVec[i]( 5);     };     return 0; }; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a method that could tell for a string like foo bar Foo
Is there a library (in any language) that can search patterns in matrixes like
There is a method Regex.Replace(string source, string pattern, string replacement) The last parameter supports
is there a method to link specific files so that I can reference them
Is there builtin method that would do this or do I always have to
I ran across this pattern in the code of a library I'm using. It
Is there any method in Java or any open source library for escaping (not
I have a lot of code that takes on the following pattern void Add(int
The pimp-my-library pattern allows me to seemingly add a method to a class by
is there a method to verify if a NSString haven't characters? example of string

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.