Created
March 29, 2019 02:05
-
-
Save sotex/5f25e5446837983c3c25c2a9d32e4ff5 to your computer and use it in GitHub Desktop.
验证引用是不是使用指针实现的。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
string s1 = "Hello World"; | |
string s2 = "你好 美女"; | |
string* ps1 = &s1; | |
string& rs1 = s1; | |
string* ps2 = &s1; | |
// 一般情况下,按照栈在虚拟进程空间高端,向地址减小的方向增长,应该是ps2<ps1 | |
string** pps = &ps1 < &ps2 ? &ps1 : &ps2; | |
pps[0] = pps[1] = pps[2] = &s2; | |
cout << rs1 <<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment