天天看點

pascal産生的hpp檔案報:E2040 Declaration terminated incorrectly

EhLib包中的一個hpp檔案DBGridEh.hpp中的一行代碼:

__property bool Eof = {read=GetEof, nodefault};

報如下錯誤:

[bcc32 Error] DBGridEh.hpp(3110): E2040 Declaration terminated incorrectly

一般情況下這種錯誤,是由于從pascal轉換到c++時變量名産生的問題,因為pascal是大小寫不敏感的,而C++是大小寫敏感的;把EOF改成Eof(或者EoF也可以)可以解決這個問題;這種問題基本上是由于系統中某個地方已經定義了EOF(預定義宏或者常量),此時編譯器就會報這種錯誤。參考:http://www.delphigroups.info/3/12/119591.html,

    would be that there exists somewhere a precompiler macro named EOF()

 that is interfering with the compile. If you can change the Pascal

 code, try changing "EOF" to "Eof" (and "BOF" to "Bof"). In C++, you

 should not have identifiers that are all-caps anyway, as that is

 commonly reserved for macros and constants.

      Pascal->C++ translation is a literal translation. Case is preserved.

 Not everything that works in Pascal will work as-is in C++. It is the

 Pascal code's responsibility to do things that can also work in C++

 when translated, and this is one of those times when it is not. There

 is nothing the compiler can do about that, because it is valid Pascal

 code and the .hpp is valid C++ code. It is just not the correct code

 from C++'s perspective because it was not set up on the Pascal side to

 be so.http://www.delphigroups.info/3/12/119591.html

繼續閱讀