我想比較兩個枚舉值,但在運行時它似乎總是評估爲真。在Table.h比較枚舉類型時的邏輯錯誤
枚舉聲明與迴歸方法獲取的狀態值:
enum TableStatus { IDLE, SEATED, ORDERED, SERVED};
class Table
{
private:
...
TableStatus status; // current status
public:
...
TableStatus getTableStatus(void);
}
在我需要比較枚舉值我一直在嘗試條件語句看起來像下面的部分:
if (tables[tableId]->getTableStatus() == TableStatus(SERVED))
我的問題如何讓這個邏輯工作。在比較Table對象的狀態到某個枚舉值將正確評估。
編輯:包括getTableStatus(void);
TableStatus Table::getTableStatus(void){
return status;
}
您顯示的代碼對於您描述的任務是正確的。如果'getTableStatus()'總是返回'SERVED',那麼在其他地方有個bug。 – 2013-03-21 18:09:27