Suppose my class has one method which has to call some other recursive method from inside it.
My .h file would look like this:
class MyClass()
{
public:
void foo();
};
My question is, which of these implementations would be better (ignoring the infinite loops):
namespace
{
void myRecursiveFunction()
{
myRecursiveFunction();
}
}
void MyClass::foo()
{
myRecursiveFunction();
}
or
void MyClass::foo()
{
std::function<void()> myRecursiveFunction =
[&] ()
{
myRecursiveFunction();
};
myRecursiveFunction();
}
, giving that myRecursiveFunction()
will only be called from foo()
?
Of course, in the real world myRecursiveFunction()
does something. I just wanted not to populate the code with unneeded information.
Is it ok for all my class to have access to myRecursiveFunction
if I only use it in one method?