-
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!!
-
>> 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
-
You may also want to look at functors (function objects).