Re: Pass a member function as argument before knowing whichinstance of class to use.

Discussion in 'C++' started by Melzzzzz, Aug 21, 2013.

  1. Melzzzzz

    Melzzzzz Guest

    On Wed, 21 Aug 2013 14:44:42 +0000, Glen Stark wrote:

    >
    > What I'd like to do is make a function that would work like this:
    >
    > void Bar::g(vector<token> toks, function<void(int) > fun_to_use)
    > {
    > for(token t : toks)
    > {
    > int key = get_key(t);
    > Foo curfoo = m_foomap[key];
    > curfoo.fun_to_use();
    > }
    > }
    >
    >
    > that does the loop and calls the appropriate function. How do I go
    > about specifying this so that I can bind the correct function to the
    > correct instance? Is this possible?


    Of course, just pass pointer to member function or make that function
    a template.
    Melzzzzz, Aug 21, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gert  Van den Eynde
    Replies:
    8
    Views:
    631
    Keith H Duggar
    Jan 26, 2004
  2. Replies:
    12
    Views:
    723
    fluden
    Feb 11, 2005
  3. Ben Kial
    Replies:
    1
    Views:
    648
    Eric Enright
    Nov 15, 2004
  4. Dwight Army of Champions

    class data member or member function argument?

    Dwight Army of Champions, Feb 21, 2010, in forum: C++
    Replies:
    4
    Views:
    1,539
    tonydee
    Feb 22, 2010
  5. Marcel Müller
    Replies:
    0
    Views:
    144
    Marcel Müller
    Aug 21, 2013
Loading...

Share This Page