开发者

Question regarding inheritance in wxWidgets

开发者 https://www.devze.com 2022-12-29 02:07 出处:网络
Currently I\'m attempting to write my own wxObject, and I would like for the class to be based off of the wxTextCtrl class.

Currently I'm attempting to write my own wxObject, and I would like for the class to be based off of the wxTextCtrl class.

Currently this is what I have:

class CommandTextCtrl : public wxTextCtrl {
    public:
        void OnKey(wxKeyEvent& event);
    private:
        DECLARE_EVENT开发者_如何学C_TABLE()
};

Then later on I have this line of code, which is doesn't like:

CommandTextCtrl *ctrl = new CommandTextCtrl(panel, wxID_ANY, *placeholder, *origin, *size);

...and when I attempt to compile the program I receive this error:

error: no matching function for call to ‘CommandTextCtrl::CommandTextCtrl(wxPanel*&, <anonymous enum>, const wxString&, const wxPoint&, const wxSize&)’

It seems that it doesn't inherit the constructor method with wxTextCtrl. Does anyone happen to know why it doesn't inherit the constructor?

Thanks in advance for any help!


C++ does not inherit constructors (you may be thinking of Python, which does;-). A class w/o explicitly declared ctors, like your CommandTextCtrl, in C++, only has default and copy ctors supplied implicitly by C++ rules.

So, you need to explicitly define a ctor with your desired signature, which basically "bounces back" to the base class's -- with the CommandTextCtrl(...): wxTextCtrl(...) {} kind of syntax, of course.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号