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

空扰寡人 提交于 2019-12-10 15:35:17

问题


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:


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

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



来源:https://stackoverflow.com/questions/4901233/is-there-anyway-to-use-a-member-function-as-a-default-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!