有没有办法返回null而不是自定义对象(不是指针)?

Ole*_*siy 4 c++ null pointers class

有没有办法在不使用指针或引用的情况下做我想做的事情?

这是代码:

Node getSmallest() {

    if (openList.empty())
        return 0;         // syntax error

    // some other code
}
Run Code Online (Sandbox Code Playgroud)

jco*_*der 7

您可以使用boost::optional返回可选值.或者等待C++ 14并使用std::optional.

  • 干嘛要等?你自己很容易实现. (2认同)

lap*_*apk 6

是.你可以抛出异常.