Return a “NULL” object if search result not found

前端 未结 8 2117
一个人的身影
一个人的身影 2020-11-28 02:23

I\'m pretty new to C++ so I tend to design with a lot of Java-isms while I\'m learning. Anyway, in Java, if I had class with a \'search\' method that would return an object

8条回答
  •  遥遥无期
    2020-11-28 03:21

    If you want a NULL return value you need to use pointers instead of references.

    References can't themselves be NULL.

    (Note to the future comment posters: Yes you can have the address of a reference be NULL if you really really try to).

    See my answer here for a list of differences between references and pointers.

提交回复
热议问题