什么意思return语句++
未能提供包含返回处于错误
一个循环结束后返回 “C++底漆第五”,295页?
尤其是,编译器没有检测到这个错误,运行时发生了什么是未定义的。
我用书样本,如:(vs2013)
#include "stdafx.h"
#include "iostream"
#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 false;
else
return true;
}
}
int _tmain(int argc, _TCHAR* argv[]) {
if (str_subrange("lyc", "talent"))
std::cout << "yes" << std::endl;
else
std::cout << "nope" << std::endl;;
system("pause");
return 0;
}
它运作良好,我想知道哪些情况是“回报”是必须的。
尝试调用'str_subrange(“”,“anything”)''。 – timrau 2014-11-05 03:55:52
请注意,你的函数只会比较'str [0]'和'str [1]' - 在第一次迭代中返回。 – GingerPlusPlus 2014-11-05 07:36:51