[英]“Using” is not solving the “hides virtual function” warning
我一直在搜寻谷歌,即使我使用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参数的新virtual int __fastcall ShowModal(void)
。
但是它仍然抱怨“隐藏虚拟功能”:
[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()
呢?
您还必须将重载版本声明为virtual
版本:
virtual int __fastcall ShowModal(System::SysUtils::Exception * E);
不知道C ++ Builder是否支持C ++ 11,但是如果支持,还尝试delete
要隐藏的重载:
virtual int __fastcall ShowModal() = delete;
而不是将其放在专用部分。
在许多方面,bcc32与C ++标准不太兼容。 每当我问自己“为什么我认为应该在C ++中使用的这项技术为什么不能在bcc32中使用?”时,我通常会认为这是另一个编译器错误。
Show
有效而ShowModal
无效的事实很有趣。 查看Vcl.Forms.hpp可以看到以下区别: Show
是使用HIDESBASE
定义的(扩展为__declspec(hidesbase)
的宏)。
将HIDESBASE添加到ShowModal应该也可以正常工作。 由于bcc32编译器很怪异,您可能还必须声明一个虚拟析构函数(如果还没有的话)。
virtual __Fastcall ~TShowException_Form() {}
之所以会发出警告,是因为您尝试做的事情经常会错误地发生,并且如果错误地做的话,这是一个严重且很难发现的错误。 也许您应该使用其他名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.