在我的课程中,我正在检查值是否为0以返回nullptr
,但我似乎无法做到这一点。无法将nullptr返回给我的类C++
Complex Complex::sqrt(const Complex& cmplx) {
if(cmplx._imag == 0)
return nullptr;
return Complex();
}
我得到的错误是:could not convert 'nullptr' from 'std::nullptr_t' to 'Complex'
我现在意识到,这nullptr
是三分球,但是,我的对象不是一个指针,有没有办法对我来说,它设置为null或类似的东西?
将返回类型设置为Complex * – madnut
也许是因为您没有在此处返回指针。你想复杂*不复杂。 – Aleks