Questions tagged «reference-binding»

3
是否可以通过const引用返回默认参数的值?
是否可以通过const引用返回默认参数的值,如以下示例所示: https://coliru.stacked-crooked.com/a/ff76e060a007723b #include <string> const std::string& foo(const std::string& s = std::string("")) { return s; } int main() { const std::string& s1 = foo(); std::string s2 = foo(); const std::string& s3 = foo("s"); std::string s4 = foo("s"); }
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.