Do the default arguments in the overload function call one or every time?

I have a question about default values ​​for overload functions in an object.

If I have a function signature as follows, will the default value be evaluated only once or each time?

class X { public: f(const RWDate& d=RWDate::now()); } // when calling f() do I get the current time each time? X z; zf(); // is the default value of d recaculated in the function call? zf(); 
+4
source share
1 answer

The arguments are replaced by default on the call site, so zf() converted to

 zf(RWDate::now()) 

Thus, the default argument is evaluated each time the function is called, and the default argument is used.

+8
source

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


All Articles