使用枚舉當我嘗試編譯此代碼與Windows 8 SDK:C++編譯錯誤的C2275結構
typedef struct {
enum { red, blue, green } eColor;
/* other params here */
} StMyStruct;
void Myfunction(StMyStruct *pst)
{
if (pst->eColor==StMyStruct.red) {
/* some code here */
}
}
但我得到這個錯誤就行如果pst->易彩== StMyStruct.red:
錯誤C2275: 'StMyStruct':非法使用這種類型作爲表達
不知道如何解決它?
我使用Windows SDK 7成功編譯此代碼,錯誤僅在Windows 8 SDK中發生。
::不解決問題,我得到相同的錯誤 – TheFrancisOne
也許VC++需要該結構有一個名稱:試着用'struct StMyStruct {...};'然後'StMyStruct :: red'。 – rodrigo
是的,這很有用,非常感謝! – TheFrancisOne