如何返回空值?我創建了一個本地字符集爲空...但有沒有不同的方式來返回一個空的左值?如何返回空char參考
char& String::operator[](int index) {
char s = NULL;
if (index > length) {
cout << "Incorect index. Enter an index 0 through (String length -1)." <<endl;
return s; // how do i return null value...this is local...
}
else {
}
}
拋出異常。 – chris
引用永遠不應該是NULL。使用指針。 – Jacob
我想你問的是錯誤的問題。我不認爲你想要返回一個空字符的引用。 –