2014-06-28 95 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

从设计角度来看,将代码注入其他人的名称空间并不是一个好习惯。当然,编译器会接受它,但它会混淆你自己的代码管理。您可以使用别人名字空间中的代码,但将其与您自己的代码分开。 –