在我的課程中,我正在檢查值是否爲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