multiple processes

This is a discussion on multiple processes within the C++ Programming forums, part of the General Programming Boards category; Hi all! Im currently trying to learn c++ from the tutorials on the site and so far so good.. There ...

  1. #1
    f76
    f76 is offline
    i will learn
    Join Date
    Jul 2004
    Posts
    1

    multiple processes

    Hi all!
    Im currently trying to learn c++ from the tutorials on the site and so far so good.. There is one feature/way of programming I would like to learn but i cant figure out what to look for... I have some vague notion of something like this....

    I would like to have several functions or loops such as animations on the move simultaniosly that can report for example collisions when they occur... I could handle these from some central function... I would like to be able to "load" and "unload" such functions on demand...

    Im not neccesarily looking for an example in code... more like the name of what Im looking for and if this is a possible way of programming...

    So far the only thing i tried in the OOP is classes and i cant figure out how they relate to the stuff im looking for..

    Thanks!!

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    >> I would like to be able to "load" and "unload" such functions on demand...
    Function pointers might be what you are looking for. For example...
    Code:
    #include <iostream>
    using namespace std;
    
    void foo(int param)
    {
        cout << "foo(" << param << ")" << endl;
    }//foo
    
    void bar(int param)
    {
        cout << "bar(" << param << ")" << endl;
    }//bar
    
    typedef void (*foobar_func_t)(int);
    // "foobar_func_t" is now a function pointer type
    
    int main()
    {
        foobar_func_t fb = NULL;
    
        for (int n = 0; n < 10; n++)
        {
            // odd numbers call bar()
            if (n & 1)
                fb = &bar;
            else
                fb = &foo;
    
            fb(n);
        }//for
    
        return 0;
    }//main
    You can read up more on function pointers here: http://www.function-pointer.org/

    gg

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    You may also want to look at functors (function objects).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tracking Multiple Processes in C Application
    By dunxton in forum C Programming
    Replies: 1
    Last Post: 05-05-2009, 03:19 AM
  2. Fork multiple processes()??
    By Paul22000 in forum C Programming
    Replies: 8
    Last Post: 11-12-2008, 03:47 PM
  3. Same pipe to multiple processes?
    By Ironic in forum C Programming
    Replies: 7
    Last Post: 10-25-2008, 10:10 AM
  4. shared libraries, datasegment and multiple processes
    By ashim_k1 in forum Linux Programming
    Replies: 1
    Last Post: 02-28-2008, 01:23 PM
  5. Multiple processes
    By cpsh007 in forum C Programming
    Replies: 10
    Last Post: 11-22-2007, 04:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21