Roland Rabien
Roland Rabien

Reputation: 8836

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

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());
};

Upvotes: 4

Views: 186

Answers (1)

ltjax
ltjax

Reputation: 16007

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

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

Upvotes: 16

Related Questions