#include <iostream>
using namespace std;
class tester
{
private:
int value;
public:
tester() : value(5){
cout << "tester at " << this << " created" << endl;
}
int get(){
return value;
}
~tester(){
cout << "tester at " << this << " deleted" << endl;
}
};
int main()
{
tester &ref1 = *new tester();
tester &ref2 = ref1;
cout << ref2.get() << endl;
delete &ref1;
cout << ref2.get() << endl;
}
tester at 0xe618f0 created
5
tester at 0xe618f0 deleted
15106864
理解上,
引用 是 指向一个对象 的指针
不能指向空,不能指向其它对象
所以课程讲解时,
引用 是 对象的别名