Is there anyway to use a member function as a default parameter?

197 views Asked by At

It tried something like this, which doesn't work. Is there a way to get a similar effect?

class A
{
public:
  int foo();
  void bar(int b = foo());
};
1

There are 1 answers

4
ltjax On BEST ANSWER

Yes. Overload the function and call the member-function in it.

void bar() { bar(foo()); }