Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么对局部变量的引用仍然有效 我在C++程序中运行以下简单程序: #include <iostream> using namespace std; string& ShowString() { string s1 = "abcd"; return s1; } int main() { string s2 = ShowString(); cout << s2 << endl; return 0; } #包括 使用名称空间std; string&ShowString() { 字符串s1=“abcd”; 返回s1; } int main() { 字符串s2=ShowString(); 不能_C++ - Fatal编程技术网

为什么对局部变量的引用仍然有效 我在C++程序中运行以下简单程序: #include <iostream> using namespace std; string& ShowString() { string s1 = "abcd"; return s1; } int main() { string s2 = ShowString(); cout << s2 << endl; return 0; } #包括 使用名称空间std; string&ShowString() { 字符串s1=“abcd”; 返回s1; } int main() { 字符串s2=ShowString(); 不能

为什么对局部变量的引用仍然有效 我在C++程序中运行以下简单程序: #include <iostream> using namespace std; string& ShowString() { string s1 = "abcd"; return s1; } int main() { string s2 = ShowString(); cout << s2 << endl; return 0; } #包括 使用名称空间std; string&ShowString() { 字符串s1=“abcd”; 返回s1; } int main() { 字符串s2=ShowString(); 不能,c++,C++,因为这是一种未定义的行为。你不能相信这个值

因为这是一种未定义的行为。你不能相信这个值