Max Kielland
Max Kielland

Reputation: 5841

"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()?

Upvotes: 2

Views: 346

Answers (3)

Josh Kelley
Josh Kelley

Reputation: 58392

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() {}

Upvotes: 2

gnasher729
gnasher729

Reputation: 52602

You get the warning because what you are trying to do happens very often by mistake and is a serious and very hard to find bug if it is done by mistake. Maybe you should use a different name.

Upvotes: 0

vladon
vladon

Reputation: 8401

You must declare overloaded version as virtual too:

virtual int __fastcall ShowModal(System::SysUtils::Exception * E);

Does not know if C++Builder supports C++11, but if it does, try also to delete overload which you want to hide:

virtual int __fastcall ShowModal() = delete;

instead of placing it into private section.

Upvotes: 0

Related Questions