how to initialize function arguments that are classes with default value

爱⌒轻易说出口 提交于 2019-12-01 03:15:47

This is supposed to not compile. You are trying to bind an rvalue to a non-const reference. Say std::wstring const & str and it should work.

You could just create a function overload:

void foo() {
    std::wstring str;
    foo(str);
}

but I really miss the point.

EDIT: I mean, that function's purpose is almost certainly to modify an input string. If you provide an empty input string that you can't access later, why bother?

You cannot bind non-const references to rvalues. Passing by value would work:

void foo(std::wstring str = std::wstring())

Or passing by reference-to-const:

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