Pourquoi ce code peut-il s'exécuter correctement dans Code :: block. La BID rapporte queRenvoi d'une référence à une variable locale
avertissement: "référence à la variable locale « tmp » retour",
mais ouput le résultat "Bonjour tout le monde" avec succès.
#include <iostream>
#include<string>
using namespace std;
const string &getString(const string &s)
{
string tmp = s;
return tmp;
}
int main()
{
string a;
cout<<getString("hello world")<<endl;
return 0;
}
double possible de [retour l'adresse de la variable locale ou temporaire] (http://stackoverflow.com/questions/2744264/returning-the-address-of-local-or-temporary-variable) – iammilind