Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No matching function for call (expects reference to pointer instead of pointer)

Tags:

c++

xcode

macos

gcc

I get the error from xcode (3.2.4)/gcc(4.0):

/Users/admin/scm/audacity/mac/../src/toolbars/DeviceToolBar.cpp: In member function 'void DeviceToolBar::ShowInputDialog()':
/Users/admin/scm/audacity/mac/../src/toolbars/DeviceToolBar.cpp:817: error: no matching function for call to 'DeviceToolBar::ShowComboDialog(wxChoice*&, wxString)'
/Users/admin/scm/audacity/mac/../src/toolbars/DeviceToolBar.h:74: note: candidates are: void DeviceToolBar::ShowComboDialog(wxChoice*, wxString&)

So it looks like it expects a reference to a pointer in ShowComboDialog, but I don't know why as the signatures are clearly normal pointers. Furthermore if it was expecting a reference to a pointer the way I am calling it should work. This is the first error, and there are no special warnings before it.

Also, this compiles in MSVC 2008 express. Please give me a clue.

//in the class def
//(only relevant portions included
class DeviceToolBar:public ToolBar {

 public:
   DeviceToolBar();
   virtual ~DeviceToolBar();
   void ShowInputDialog();
 private:
   void ShowComboDialog(wxChoice *combo, wxString &title);

   wxChoice *mInput;
};

//in the cpp file
void DeviceToolBar::ShowInputDialog()
{
   ShowComboDialog(mInput, wxString(_("Select Input Device")));
}

void DeviceToolBar::ShowComboDialog(wxChoice *combo, wxString &title)
{
//...
}
like image 414
Michael Chinen Avatar asked Dec 09 '22 11:12

Michael Chinen


1 Answers

The problem is not the first parameter; its the second. You're passing in a temporary wxString, but the function is expecting a reference. C++ will automatically convert a temporary to a const reference, but it cannot convert it to a reference. You need to make ShowComboDialog take a const reference as its second parameter.

like image 59
Daniel Gallagher Avatar answered Dec 11 '22 23:12

Daniel Gallagher