What should the return type be when the function might not have a value to return?

后端 未结 6 966
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 17:25

In the old days, you might have a function like this:

const char* find_response(const char* const id) const;

If the item could not be found

6条回答
  •  -上瘾入骨i
    2021-01-01 17:57

    I think the second way is better. Or you can write like this:

    int find_response(const std::string& id, std::string& value) const;
    

    if this function return -1, it tells that you don't find the response.

提交回复
热议问题