views:

602

answers:

4

Environment : Visual Studio 2008 , wxWidgets 2.8.10 , Vista 64

Code

header.h

#include <wx/wx.h>

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

main.cpp

#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 ?

A: 

instead of this line:

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

try this:

class CSend { CSend(wxString& name = wxString()); ~CSend(); };
Idan K
not sure why this was downvoted- it's a legitimate solution (though possibly not the best one)
arolson101
A: 

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 = _(""));

or

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

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

CSend(wxString& name = wxEmptyString);

SteveL
Sujay Ghosh
arolson101
+3  A: 

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

CSend(wxString& name = "");

to

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.

Tadeusz Kopec
A: 

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...

http://www.gamedev.net/community/forums/topic.asp?topic_id=403518

buzz3791