Is it possible to set an object to null?

前端 未结 5 1901
一个人的身影
一个人的身影 2020-12-01 07:39

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?

5条回答
  •  时光说笑
    2020-12-01 08:16

    "an object" of what type?

    You can certainly assign NULL (and nullptr) to objects of pointer types, and it is implementation defined if you can assign NULL to objects of arithmetic types.

    If you mean objects of some class type, the answer is NO (excepting classes that have operator= accepting pointer or arithmetic types)

    "empty" is more plausible, as many types have both copy assignment and default construction (often implicitly). To see if an existing object is like a default constructed one, you will also need an appropriate bool operator==

提交回复
热议问题