xcode 没有匹配的调用函数(期望引用指针而不是指针)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4839639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:09:14  来源:igfitidea点击:

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

c++xcodemacosgcc

提问by Michael Chinen

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

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

所以看起来它希望引用 ShowComboDialog 中的一个指针,但我不知道为什么,因为签名显然是正常的指针。此外,如果它期望对指针的引用,我调用它的方式应该可以工作。这是第一个错误,在此之前没有特殊警告。

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

此外,这在 MSVC 2008 express 中编译。请给我一个线索。

//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)
{
//...
}

回答by Daniel Gallagher

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 constreference, but it cannot convert it to a reference. You need to make ShowComboDialogtake a const reference as its second parameter.

问题不在于第一个参数;它的第二个。您正在传入一个临时wxString,但该函数需要一个引用。C++ 会自动将临时文件转换为const引用,但不能将其转换为引用。您需要将ShowComboDialogconst 引用作为其第二个参数。

回答by James McNellis

Your ShowComboDialogtakes a wxStringby non-const reference and you are trying to pass a temporary object as an argument to this parameter. You can only bind const references to temporary objects.

ShowComboDialog采用wxString非常量引用,并且您正尝试将临时对象作为参数传递给此参数。您只能将 const 引用绑定到临时对象。

You either need to change ShowComboDialogto take its second argument either by value (wxString) or by const reference (const wxString&) or you need to create a variable for the wxStringthat you create when you call the function and then pass (a reference to) that variable instead.

您要么需要更改ShowComboDialog为通过值 ( wxString) 或通过常量引用 ( const wxString&)获取其第二个参数,要么需要为wxString调用函数时创建的变量创建一个变量,然后改为传递(引用)该变量。