C++ primer(第五版) 练习 6.30 个人 code

来源:互联网 发布:关于mac版千牛问题. 编辑:程序博客网 时间:2024/06/18 08:51


C++ primer(第五版) 练习 6.30

题目:编译第200页的str_subrange 函数,看看你的编译器是如何处理函数中的错误的。

答:error C2561: “str_subrange”: 函数必须返回值; 参见“str_subrange”的声明

#include <string>using std::string;bool str_subrange(const string &str1, const string &str2){if (str1.size() == str2.size())return str1 == str2;auto size = (str1.size() < str2.size()) ? str1.size() : str2.size();for (decltype(size)i = 0; i != size; ++i){if (str1[i] != str2[i])return;//函数必须返回值}}

执行结果:


0 0
原创粉丝点击