Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道如何取消引用。例如:我有
class Student {...};
然后我创建对象:
Student Caroline;
后来我参考:
Student &princess = Caroline;
从现在开始,我可以使用 Princess 或 Caroline 来查看我的对象,但我决定不再叫 Her Princess,我想删除这个引用:怎么做?我知道我不能更改引用,但有人告诉我不能调用它。提前谢谢帮助
不可能(据我所知)。一旦引用指向一个对象,就不会改变它。
另一种方法是指针:
Student *princess = &Caroline; princess->name = "Still Caroline"; princess = &Sarah; princess->name = "Still Sarah";