Can a member function be used as the default parameter?

He tried something like this that doesn't work. Is there any way to get a similar effect?

class A { public: int foo(); void bar(int b = foo()); }; 
+4
source share
1 answer

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

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

+16
source

Source: https://habr.com/ru/post/1338463/


All Articles