Take the 2-minute tour ×

Environment : Visual Studio 2008 , wxWidgets 2.8.10 , Vista 64



#include <wx/wx.h>

class CSend
    CSend(wxString& name = "");


#include "header.h"

void main()
   CSend dlg(wxString("Hi"));

When I compile this program I get the following error

error C2440: 'default argument' : cannot convert from 'const char [1]' to 'wxString &'

Can anyone please help me ?

share|improve this question
Which wxWidgets version are you using? –  Jaime Pardos Aug 14 '09 at 11:36
I am using wxWidgets 2.8.10 –  Sujay Ghosh Aug 14 '09 at 14:26

4 Answers 4

If you're not using a Unicode build of wxWidgets, change

Microsoft Visual Studio 2008->Project->Properties->Configuration Properties->General->Character Set

to "Use Multi-Byte Character Set".

More details can be found here...


share|improve this answer

Do you really wish to change the value of wxString name that is passed to CSend constructor? If not, change

CSend(wxString& name = "");


CSend(const wxString& name = "");

I don't know the wxString class, but I guess it has a constructor from char *. It allows you to create a temporary of type wxString that is used as a default argument for CSend constructor, but it can't be bound to non-const reference - only to const.

share|improve this answer

You just need to quote your strings with _() if you want them to be translatable and wxT() if you don't, this is for Unicode compatibility I think. In your case this would be:

CSend(wxString& name = _(""));


CSend(wxString& name = wxT(""));

As this is an empty string you might want to instead say:

CSend(wxString& name = wxEmptyString);

share|improve this answer
When I compile this code, I get the following error , "error C2440: 'default argument' : cannot convert from 'const wxChar *' to 'wxString &'" –  Sujay Ghosh Aug 13 '09 at 15:51
You'd have to do CSend(const wxString& name = wxEmptyString) because wxEmptyString is a const wxChar*. Actually, you need const in all these examples. –  arolson101 Sep 2 '09 at 17:19

instead of this line:

class CSend { CSend(wxString& name = ""); ~CSend(); };

try this:

class CSend { CSend(wxString& name = wxString()); ~CSend(); };
share|improve this answer
not sure why this was downvoted- it's a legitimate solution (though possibly not the best one) –  arolson101 Sep 2 '09 at 17:25

Your Answer


