在我的代码中,我检查对象是否为空/空。
有没有办法将对象设置为空?
最佳答案
一个类的对象不能设置为NULL;但是,您可以将指针(包含对象的内存地址)设置为 NULL。
你问的不能做的例子:
Cat c;
c = NULL;//Compiling error
你可以做什么的例子:
Cat c;
//Set p to hold the memory address of the object c
Cat *p = &c;
//Set p to hold NULL
p = NULL;
关于c++ - 是否可以将对象设置为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3030829/