#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
const char* funA()
{
return "aa"; // where does system to store this temporary variable?
}
// this is not an valid function
const char* funB()
{
string str("bb");
return str.c_str();
}
int _tmain(int argc, _TCHAR* argv[])
{
cout << funA() << endl;
cout << funB() << endl; // invalid
return 0;
}
質問> 関数内のローカル変数へのポインターまたは参照を返すべきではありません。したがって、戻り変数「aa」は funA の関数内のローカル変数ではありません。では、それは何ですか?
ありがとうございました