Search code examples
overloadingc++builderusingc++builder-xe7

"Using" is not solving the "hides virtual function" warning


I have been googling high and low and can't find a solution that will remove the warning, even when I use the using directive.

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);
};

I want to hide the original virtual int __fastcall ShowModal(void) and expose a new one taking an Exception parameter.

But it still complaints on "hides virtual function":

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

I have also tried using TForm::ShowModal; but with the same result. Any ideas of how to solve this warning?


EDIT
I found out that it works perfectly well if I override the show() method instead:

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);
};

So why isn't it working with ShowModal()?


Solution

  • bcc32 is, in many respects, not very compliant with the C++ standard. Whenever I find myself asking, "Why does this technique that I think should work in C++ not work in bcc32?", I usually assume it's yet another compiler bug.

    The fact that Show works while ShowModal doesn't is interesting. Looking at Vcl.Forms.hpp shows the difference: Show is defined with HIDESBASE (a macro that expands to __declspec(hidesbase)).

    Adding HIDESBASE to your ShowModal should work as well. You may also have to declare a virtual destructor, if you don't already have one, due to bcc32 compiler weirdness.

    virtual __Fastcall ~TShowException_Form() {}