开发者

C++ default arguments in function overload evaluated once or each time?

I have a question on defaults 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;
z.f();

// 开发者_Go百科is the default value of d recaculated in the function call?
z.f();


The default arguments are substituted at the call site, so z.f() is transformed into

z.f(RWDate::now())

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜