【问题标题】:Bypassing ambiguity between 2 classes绕过两个类之间的歧义
【发布时间】:2012-08-25 17:14:40
【问题描述】:

我已经从 Rad studio 的官方网站下载了 TVersionInfo VCL,并在我的 IDE 中成功安装了它,因为它们出现在我的工具箱面板中。将它粘贴到我的项目中并第一次尝试构建它。我确信它会构建好,因为我已经运行了它附带的测试项目。没问题。 但是在我的项目编译过程中出现了错误。由于使用 Fib plus 包进行 interbase db 访问连接,这一切都发生在我身上。 以下是消息中出现的错误:

Checking project dependencies...
Compiling Invoice.cbproj (Debug configuration)
[BCC32 Error] VersionInfoUI.h(24): E2015 Ambiguity between 'TVersionInfo' and 'Ib_services::TVersionInfo'
  Full parser context
    main.cpp(10): #include about.h
    about.h(11): #include D:\CB2010_VCL\VersionInfo\VersionInfoUI.h
    VersionInfoUI.h(11): class TCustomVersionInfoLabel
[BCC32 Error] VersionInfoUI.h(25): E2015 Ambiguity between 'TVersionInfo' and 'Ib_services::TVersionInfo'
  Full parser context
    main.cpp(10): #include about.h
    about.h(11): #include D:\CB2010_VCL\VersionInfo\VersionInfoUI.h
    VersionInfoUI.h(11): class TCustomVersionInfoLabel
[BCC32 Error] VersionInfoUI.h(39): E2015 Ambiguity between 'TVersionInfo' and 'Ib_services::TVersionInfo'
  Full parser context
    main.cpp(10): #include about.h
    about.h(11): #include D:\CB2010_VCL\VersionInfo\VersionInfoUI.h
    VersionInfoUI.h(11): class TCustomVersionInfoLabel
[BCC32 Error] about.h(16): E2015 Ambiguity between 'TVersionInfo' and 'Ib_services::TVersionInfo'
  Full parser context
    main.cpp(10): #include about.h
    about.h(13): class TfAbout
Failed
Elapsed time: 00:00:04.0  

我认为 FIB IB Service 类也具有相同的类名,因此两个类名之间存在冲突。如何解决这个问题?如何让两个类像使用命名空间或其他东西一样一起工作?

【问题讨论】:

  • 我需要在namespace MyVerInfo{ ... } and use MyVerInfo::TVersionInfo 之类的命名空间中包含class PACKAGE TVersionInfo : public TComponent 吗?
  • 尝试像#if defined (VersionInfoComponentH) namespace verinfo{ #endif 一样但没有效果!
  • 到目前为止还需要更改他们的类名吗?前缀 MyTVersion?

标签: c++ c++builder c++builder-2010


【解决方案1】:

Delphi 为 VCL 组件生成的 .hpp 文件被包装在命名空间中。问题是他们还倾向于在它们的底部使用using namespace ... 语句将所有内容转储到全局命名空间中,这完全违背了使用命名空间的目的。如果您查看此类 .hpp 文件的底部,您将看到 #ifdef 语句,这些语句显示您可以在项目中定义哪些值来禁用此行为。另一种方法是在设计时根本不使用TVersionInfo。在运行时代码中动态创建它,而不是通过 new 运算符,然后您可以指定它来自哪个命名空间。

【讨论】:

  • 似乎唯一有命名空间的文件是versioninforegistration.cpp,内容看起来像namespace Versioninforegistration { void __fastcall PACKAGE Register(void) { const UnicodeString ComponentPaletteLocation = L"VersionInfo"; //
  • 在运行时使用代码创建它没有成功。因为当我包含它的包含文件时,比如说,#include "VersionInfoComponent.h" 它有类定义和错误。
  • 你可以去看看,仓库在这里:radstudiodemos.svn.sourceforge.net/viewvc/radstudiodemos/…
  • 我最好使用来自Bluewater的日本轻量级类。工作良好。
猜你喜欢
  • 2012-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 2011-01-15
  • 1970-01-01
相关资源
最近更新 更多