hi. In order to call a member function recursively, what is the syntax? for example:
1 2 3 4 5 6 7 8 9 10
class foo
{
public:
void recursiveCall ();
}
void foo::recursiveCall ();
{
recursiveCall (); //here: how would you call this function again? I think you would need an object....but I'm not exactly sure...
}
You have a syntax error on line 7 with that extra semicolon, but otherwise I think it works as written (the call, at least - the infinite recursion is another matter).
If it needs access to class member data than a standard non-static member function is fine.
Of course you will need an object to call it. This can be the current object. A non-static member function can be considered the same as the static one except that there is a (hidden) extra argument to the function. This hidden argument is a pointer to the current object.
You can call it recursively with with just recursiveCall() as you have done. Or to make it clear you can use
this->recursiveCall() which is the same thing.
Since the class member data is accessed via pointer it is the same data for every function call. Data passed as arguments by value get a new copy for each recursive call and this can be part of the way a recursive algorithm works.