views:

31

answers:

1

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_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!

+5  A: 

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.

Alex Martelli
Ah! Thank you! I'm somewhat new to C++ (I'm migrating over from Java and Python).
celestialorb
@celestialorb, you're welcome -- I'm a C++ expert who's mostly been using Python for the last several years, myself (wish I knew Java's details as deeply as I do C++'s and Python's, but I just don't have enough real-world experience in it... I _think_ Java, like C++, doesn't inherit constructors, but, I wouldn't bet my shirt on it;-).
Alex Martelli