我一直在谷歌上搜索,但找不到可以删除警告的解决方案,即使我使用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/