Search code examples
c++wxwidgets

No matching constructor for class initialization


I have this class :

class instaStalkPanel : public wxPanel {
private:
    
public:
    instaStalkPanel(wxWindow *parent, wxWindowID id, wxPoint &pos, wxSize &size, long style, const wxString &name);
    
    wxDECLARE_EVENT_TABLE();
};

Now I'm trying to initialize a pointer variable of this class like this, in another class called instaStalkFrame :

mainPanel = new instaStalkPanel(this, ID_PANEL_MAIN, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, "panel");

The error it gives me :

No matching constructor for initialization of 'instaStalkPanel'

Any ideas why this happens ?

  • Note:

The constructor function :

instaStalkPanel::instaStalkPanel(wxWindow *parent, wxWindowID id, wxPoint &pos, wxSize &size, long style, const wxString &name) : wxPanel(parent, id, pos, size, style, name){
    
}

Solution

  • You're trying to bind non-const references (pos and size) to const objects.
    Make the parameters const wxPoint& and const wxSize&.