把引用对象压入栈
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;