爲什麼引用不能在C++中重新初始化,而指針可以重新初始化?爲什麼引用不能在C++中重新初始化?
int x=5;
int y=6;
int *p1;
p1 = &x;
p1 = &y; //re-initializing the pointer but same can not be done with references
int &r1 =x;//can be initialized only once
爲什麼引用不能在C++中重新初始化,而指針可以重新初始化?爲什麼引用不能在C++中重新初始化?
int x=5;
int y=6;
int *p1;
p1 = &x;
p1 = &y; //re-initializing the pointer but same can not be done with references
int &r1 =x;//can be initialized only once
查看相關問題http://stackoverflow.com/questions/1305055/reference-initialization-in-c – user1929959
非常簡短的回答:因爲如果他們在哪裏,他們將有完全重複的指針功能(可變重定向) –