#include <iostream>
#include <string>
using namespace std;
string
crash()
{
}
int
noCrash()
{
}
int
main()
{
crash(); // crashes
// noCrash(); // doesn't crash
return 0;
}
函数 crash() 在 Mingw g++ 4.6.2 中崩溃,函数 noCrash() 执行时没有问题。为什么没有 return 语句返回字符串的函数会崩溃?
最佳答案
两者都是未定义的行为,即使是noCrash
也会崩溃。
关于c++ - 返回 std::string 的函数在没有 return 语句的情况下崩溃,这与返回 int 且没有 return 语句的函数不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11096027/