2014-06-28 103 views
1

我正在嘗試在RAD Studio XE5中使用帶有C++ Builder的HP APDK。我需要從HP的基類SystemServices中派生出一個類PlatformServices(或者我選擇的任何名稱)。這裏是我的頭PlatformServices.h:C++ Builder E2303預期的類型名稱

/***************************************************************************\ 
    APDK Platform Services 
\***************************************************************************/ 

#ifndef _H_PLATFORMSERVICES 
#define _H_PLATFORMSERVICES 

#include "header.h"       // HP APDK General Header 

// class SystemServices { 
// }; 

class PlatformServices : public SystemServices { 
    ~PlatformServices(); 
    PlatformServices(); 
}; 

#endif 

編譯原來的樣子,我得到的錯誤:

[bcc32 Error] PlatformServices.h(13): E2303 Type name expected 
    Full parser context 
    PlatformServices.cpp(5): #include PlatformServices.h 
    PlatformServices.h(13): class PlatformServices 

但是,如果我註釋掉的#include並取消定義爲一個空類名爲SystemServices ,代碼編譯沒有錯誤。

我可以按原樣預處理代碼(在項目管理器中,右鍵單擊PlatformServices並選擇預處理),我可以看到#include定義了格式良好的SystemServices類。

我也禁用了預編譯頭文件。

這看起來像一個編譯器錯誤,但它是一個糟糕的工作者,責怪他的工具。我簡直不敢相信C++ Builder會扼殺這些基本的東西,但我看不出我做錯了什麼。幫幫我!

P.S.我已經發布了完整的代碼和項目文件在:https://www.dropbox.com/s/sn1377y59r3idtz/apdk.zip

回答

3

SystemServicesapdk命名空間中聲明,所以你需要指定在你的代碼,無論是直接:

class PlatformServices : public apdk::SystemServices 

或者用using namespace聲明:

using namespace apdk; 

class PlatformServices : public SystemServices 
+0

正確。具體來說,使用名稱空間宏APDK_BEGIN_NAMESPACE和APDK_END_NAMESPACE包含源文件和頭文件的內容,就像基類SystemServices的源文件和頭文件一樣,可以解決該問題。謝謝。 –

+0

從設計角度來看,將代碼注入其他人的名稱空間並不是一個好習慣。當然,編譯器會接受它,但它會混淆你自己的代碼管理。您可以使用別人名字空間中的代碼,但將其與您自己的代碼分開。 –