把引用对象压入栈
stack<int> a;
int m = 1;
int &b = m;//压入引用对象,
a.push(b);
b = 2;
int t = a.top();
cout << *t;
这个时候打印的是1;
stack<int*> a;
int m = 1;
int *b = &m;
a.push(b);
*b = 2;
int *t = a.top();
cout << *t;
这个时候打印是2;
把引用对象压入栈
stack<int> a;
int m = 1;
int &b = m;//压入引用对象,
a.push(b);
b = 2;
int t = a.top();
cout << *t;
这个时候打印的是1;
stack<int*> a;
int m = 1;
int *b = &m;
a.push(b);
*b = 2;
int *t = a.top();
cout << *t;
这个时候打印是2;
1702

被折叠的 条评论
为什么被折叠?