여기서 실제로 발생하는 상황을 명확하게 파악할 수없는 시나리오에서 나타납니다.cpp에서 문자열 참조 처리
// 이것은 CPP 프로그램입니다.
#include <iostream>
#include <time.h>
using namespace std;
int main() {
std::string nums ("1234567890"); //What happens with this memory??
std::string alpha ("abcdefghijklmnopqrstuvwxyz");
std::string &charStr = nums;
charStr = alpha;
cout <<"nums : " << nums <<endl;
cout <<"alpha :" << alpha <<endl;
cout <<"charStr :" << charStr <<endl;
return 0;
}
출력은 다음과 같습니다
nums :
알파 ABCDEFGHIJKLMNOPQRSTUVWXYZ :
charStr ABCDEFGHIJKLMNOPQRSTUVWXYZ :시 nums에 할당 된 메모리에 어떻게됩니까
ABCDEFGHIJKLMNOPQRSTUVWXYZ 이니 시아 라이 제이션?
스택에 할당됩니다. – leppie