我正在尝试编写一个函数来检查对象是否存在:
bool UnloadingBay::isEmpty() {
bool isEmpty = true;
if(this->unloadingShip != NULL) {
isEmpty = false;
}
return isEmpty;
}
我对C++很陌生,不确定我的Java背景是否让我产生了混淆,但编译器报错了:
UnloadingBay.cpp:36: error: no match for ‘operator!=’ in ‘((UnloadingBay*)this)->UnloadingBay::unloadingShip != 0’
我似乎无法弄清楚为什么它不起作用。
这是类UnloadingBay的声明:
class UnloadingBay {
private:
Ship unloadingShip;
public:
UnloadingBay();
~UnloadingBay();
void unloadContainer(Container container);
void loadContainer(Container container);
void dockShip(Ship ship);
void undockShip(Ship ship);
bool isEmpty();
};
return this->unloadingShip == NULL;
。 - Ed S.