Search code examples
c++c++11wxwidgets

no instance of constructor wxTextValidator matches instance


I need to validate text within a wxTextControl as a float or an int (for starters). I will eventually need float > 0, float >= 0 etc etc. My idea was to create an enum defining all of my scenarios and create the val within a function. I'm having trouble getting started, as the declaration of the wxTextValidator throws an error.

enum class glValidate { glInt, glPosInt, gl0PosInt, glFloat, glPosFloat, gl0PosFloat, glString};

wxValidator GuiLib::CreateValidator(std::wstring* default_value, glValidate flag) {
    wxArrayString numberArray;
    numberArray.Add(wxT("0"));
    numberArray.Add(wxT("1"));
    numberArray.Add(wxT("2"));
    numberArray.Add(wxT("3"));
    numberArray.Add(wxT("4"));
    numberArray.Add(wxT("5"));
    numberArray.Add(wxT("6"));
    numberArray.Add(wxT("7"));
    numberArray.Add(wxT("8"));
    numberArray.Add(wxT("9"));

wxTextValidator val(wxFILTER_NONE, default_value);

switch (flag) {
    case glValidate::glInt:       
        numberArray.Add(wxT("-"));
        val.SetStyle = wxFILTER_INCLUDE_LIST;
        val.SetIncludes(numberArray);
        break;
    case glValidate::glPosInt:
        val.SetStyle = wxFILTER_INCLUDE_LIST;
        val.SetIncludes(numberArray);
        break;
    }
    etc..
}

I recognize that even this simple scenario is busted because the glInt case would allow "123-456", but I think I can deal with that via an event handler once I get this part working. The problem is that I'm getting an error message stating

no instance of constructor "wxTextValidator::wxTextValidator" matches the argument list


Solution

  • I was fooled by Visual Studio. The problem with the above code is that default_value is wstring, when it needs to be wxString*. Visual Studio highlighted ```wxFILTER_NONE''', which lead me think the problem was there!

    After rejigging to make fix the string param it works. Well it compiles - now I need to get the validation working as desired...