overloading - "Using"未解决 "hides virtual function"警告

标签 overloading c++builder using c++builder-xe7

我一直在谷歌上搜索,但找不到可以删除警告的解决方案,即使我使用using指令。

class TShowException_Form : public TForm {

    __published: // IDE-managed Components
        TButton *Send_Button;
        TButton *Cancel_Button;
        TLabel  *Message_Label;

    private:    // User declarations
        using TCustomForm::ShowModal;
        //using TForm::ShowModal;

    public:     // User declarations
            __fastcall TShowException_Form(TComponent* Owner);
        int __fastcall ShowModal(System::Sysutils::Exception *E);
};

我想隐藏原来的virtual int __fastcall ShowModal(void)并公开一个带有 Exception 参数的新参数。

但它仍然提示“隐藏虚拟函数”:

[bcc32 Warning] TShowExceptionForm.h(32): '_fastcall TShowException_Form::ShowModal(Exception *)' hides virtual function '_fastcall TCustomForm::ShowModal()'

我也尝试过using TForm::ShowModal;但结果相同。 关于如何解决此警告有什么想法吗?


编辑
我发现如果我覆盖show(),它就可以很好地工作。方法:

class TShowException_Form : public TForm {

    __published: // IDE-managed Components
        TButton *Send_Button;
        TButton *Cancel_Button;
        TLabel  *Message_Label;

    private:    // User declarations
        using TForm::ShowModal;
        using TForm::Show;

    public:     // User declarations
            __fastcall TShowException_Form(TComponent* Owner);
        int __fastcall Show(System::Sysutils::Exception *E);
};

那么为什么它不能与 ShowModal() 一起使用呢? ?

最佳答案

bcc32 在很多方面都不太符合 C++ 标准。每当我发现自己问“为什么我认为应该在 C++ 中工作的这种技术在 bcc32 中不起作用?”时,我通常会认为这是另一个编译器错误。

事实上,Show 可以工作,而 ShowModal 则不行,这一点很有趣。查看 Vcl.Forms.hpp 会发现差异:Show 是用 HIDESBASE (扩展为 __declspec(hidesbase) 的宏)定义的。

将 HIDESBASE 添加到您的 ShowModal 中应该也可以。由于 bcc32 编译器的怪异,如果您还没有虚拟析构函数,您可能还必须声明一个虚拟析构函数。

virtual __Fastcall ~TShowException_Form() {}

关于overloading - "Using"未解决 "hides virtual function"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32892085/

相关文章:

C# dll 中的 C# 转换异常

c++ - 基本类型数组的迭代器类型

c# - MSDN Crystal 报表教程中缺少 hierarchical_grouping 的 Using 指令

scala - 重载具有多个参数列表的方法是否违法?

Groovy 运算符重载增量/减量错误

java - Java 中能否自动将一个类的对象转换为子类并调用重载方法?

C++ 生成器 WMI : Invalid Query

C++ builder 如何配置编译器只输出 exe?

c# - 如何使用 Activator.CreateInstance 将泛型实例化为 using block 的一部分?

c# - 是否可以像在 VB.NET 中一样在 C# 中导入静态类?