本文介紹了是否可以將對象設置為空?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
進一步在我的代碼中,我檢查對象是否為空/空.
Further in my code, I check to see check if an object is null/empty.
有沒有辦法將對象設置為空?
Is there a way to set an object to null?
推薦答案
類的對象不能設置為NULL;但是,您可以將指針(包含對象的內存地址)設置為 NULL.
An object of a class cannot be set to NULL; however, you can set a pointer (which contains a memory address of an object) to NULL.
你不能做的事情的例子:
Example of what you can't do which you are asking:
Cat c;
c = NULL;//Compiling error
您可以執行的操作示例:
Example of what you can do:
Cat c;
//Set p to hold the memory address of the object c
Cat *p = &c;
//Set p to hold NULL
p = NULL;
這篇關于是否可以將對象設置為空?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!