2012-05-24 74 views
0

我的頭文件中有一些錯誤,我不知道該如何解決,因爲我對C++相當陌生。C++頭文件 - 語法問題

這裏是頭文件的代碼:

#pragma once 

typedef unsigned int uint; 

class DCEncryption 
{ 
public: 
    static char* manageData(char*, char*, uint); 

private: 
    static int max(int, int); 
    static uint leftRotate(uint, int); 
}; 

這裏是錯誤:

- dcencryption.h(12): error C2062: type 'int' unexpected 
- dcencryption.h(12): error C2334: unexpected token(s) preceding ':'; skipping apparent function body 
- dcencryption.h(12): error C2760: syntax error : expected '{' not ';' 
- dcencryption.h(13): error C2144: syntax error : 'uint' should be preceded by '}' 
- dcencryption.h(13): error C2143: syntax error : missing ')' before ';' 
- dcencryption.h(13): error C2059: syntax error : ')' 
- dcencryption.h(13): error C2143: syntax error : missing ';' before ')' 
- dcencryption.h(13): error C2238: unexpected token(s) preceding ';' 
+2

我相信在一些編譯器中,'uint'是'unsigned int'的保留關鍵字。我可能是錯的,但嘗試改變你的命名方案。 – Drise

+0

@Drise - 聽起來不太可能,除非你記得事實上是C#。 –

+0

@JirkaHanika無論如何,這似乎是某種宏觀或'#define'衝突。我仍然責備命名衝突。 – Drise

回答

4

你可能在Windows和你已經直接或間接地包含windef.h(通過windows.h,可能)從您的主要.cpp文件包括顯示的文件之前。

恰巧maxwindef.h中定義的宏,在您的上下文中不能很好地擴展。

這在其他一些平臺上也很容易發生。

+0

如果WinDef.h中的'max'宏確實存在問題,那麼可以通過定義'NOMINMAX'來關閉它(和'min'宏),無論是項目範圍還是包含任何Windows頭文件之前。 – Praetorian

+0

非常感謝。我改變了方法的名稱,所有8個錯誤都消失了。再次感謝。 –