我想寫一個對象是否存在,將檢查功能:我怎麼能檢查對象是否存在於C++
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();
};
正在卸載船舶類功能?你能發佈你的類聲明嗎? – 2010-09-04 03:14:52
no unloadingShip是unLoadingBay的一個屬性,它是isEmpty是其成員的類 – 2010-09-04 03:20:16
pharma_joe:作爲一般提示:您在Java中學到的所有內容?算了吧。它不會幫助你在C++中。 – greyfade 2010-09-04 04:45:48